Skip to content

How to refer to a list member by variable

3 messages · Reitsma, Rene - COB, Gavin Simpson, Hadley Wickham

#
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))
[1]  1  2  3  4  5  6  7  8  9 10
[1]  1  2  3  4  5  6  7  8  9 10
NULL
NULL

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

RR
#
On Mon, 2008-12-01 at 10:53 -0800, Reitsma, Rene - COB wrote:
foo[[goo]]

See ?`[[` for more details. Not sure if there is an incantation that
will work with '$' in this case.

HTH

G
#
On Mon, Dec 1, 2008 at 12:53 PM, Reitsma, Rene - COB
<reitsmar at bus.oregonstate.edu> wrote:
foo[[goo]]

which you'll find in ?"$" under the heading "Recursive (list-like) objects"

Hadley