One of the reasons lists are useful is that you can put various things in them and then you have an object name that you can hard code into your program, yet still use variables to find objects in that list. That is you do not need to directly use the get function at all.
foo[[var]] If you ever think this is not true, just make a new list and put your old list into it, and you can start using variables to look up your old list. lname <- "foo" bar <- list( foo= list(A = c(1,3), B =c(1, 2), C = c(3, 1)) ) bar[[lname]][[var]] --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On December 17, 2014 7:24:56 PM PST, ce <zadi...@excite.com> wrote: >Dear all, > >If I have a list like this how I can get an object of it with a >variable : > >foo<-list(A = c(1,3), B =c(1, 2), C = c(3, 1)) >var <- "A" > >get(paste("foo$",'A',sep='')) >Error in get(paste("foo$", "A", sep = "")) : object 'foo$A' not found > >______________________________________________ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.