[R] How to refer to a list member by variable

Reitsma, Rene - COB reitsmar at bus.oregonstate.edu
Mon Dec 1 19:53:46 CET 2008


Dear All,

I'm hoping one of you can help me with the following R problem. I'm
trying to refer to a member of a list by variable. However, this seems
not to work:

foo=list(first=c(1:10),second=c(11:20))

> foo$first
 [1]  1  2  3  4  5  6  7  8  9 10

> foo$"first"
 [1]  1  2  3  4  5  6  7  8  9 10

> goo=c("first")

> foo$goo
NULL

> foo$goo[1]
NULL

I'm sure I'm missing something quite elementary. Perhaps you can help?

RR



More information about the R-help mailing list