[R] Access and assign list sub-elements using a string such as "l$a$b"
Petr Pikal
petr.pikal at precheza.cz
Thu Jun 15 16:56:59 CEST 2006
Hi
very, very close
On 15 Jun 2006 at 13:27, Gregory Jefferis wrote:
Date sent: Thu, 15 Jun 2006 13:27:05 +0100
From: Gregory Jefferis <gsxej2 at cam.ac.uk>
To: "r-help-request at stat.math.ethz.ch" <r-help-request at stat.math.ethz.ch>
Forwarded to: <r-help at stat.math.ethz.ch>
Forwarded by: Gregory Jefferis <gsxej2 at cam.ac.uk>
Date forwarded: Thu, 15 Jun 2006 14:54:13 +0100
Subject: [R] Access and assign list sub-elements using a string such as
"l$a$b"
> If I have a list I can set a sub-element as follows on the command
> line:
>
> people=list()
> people$tom$hair="brown"
> people
>
> But what if I have a string containing the name of the sub-element
> that I want to access?
>
> subel= "people$tom$hair"
>
> get(subel) # returns error
> assign(subel,"red") # silent but doesn't change list
> people
See what happens when
people<-assign(subel, "red")
HTH
Petr
>
> The attempts above using assign/get won't do what I am trying to do
> [nor according to the help should they]. I would be very grateful for
> any suggestions. Many thanks,
>
> Greg.
>
> --
> Gregory Jefferis, PhD and:
> Research Fellow
> Department of Zoology St John's
> College University of Cambridge
> Cambridge Downing Street CB2 1TP
> Cambridge, CB2 3EJ United Kingdom
>
> Lab Tel: +44 (0)1223 336683 Office: +44 (0)1223
> 339899 Lab Fax: +44 (0)1223 336676
>
> http://www.zoo.cam.ac.uk/zoostaff/jefferis.html
> gsxej2 at cam.ac.uk
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list