[R] Reference variables by string in for loop

2011-04-29 Thread Michael Bach
Dear R Users, I am trying to get the following to work better: namevec - c(one, two, three) for (name in namevec) { namedf - eval(parse(text=paste(name, _df, sep=))) ... ... } The rationale behind it being that I created variables with names one_df, two_df and three_df earlier in

Re: [R] Reference variables by string in for loop

2011-04-29 Thread Kenn Konstabel
On Fri, Apr 29, 2011 at 1:03 PM, Michael Bach pha...@gmail.com wrote: Dear R Users, I am trying to get the following to work better: namevec - c(one, two, three) for (name in namevec) {    namedf - eval(parse(text=paste(name, _df, sep=)))    ...    ... } The rationale behind it being

Re: [R] Reference variables by string in for loop

2011-04-29 Thread Nick Sabbe
Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Bach Sent: vrijdag 29 april 2011 12:03 To: r-help@r-project.org Subject: [R] Reference variables by string

Re: [R] Reference variables by string in for loop

2011-04-29 Thread Michael Bach
Nick Sabbe nick.sa...@ugent.be writes: ObjectsOfInterest- list(one_df, two_df, three_df) for(namedf in ObjectsOfInterest){...} I see. This is also more readable and traceable for others. or probably even better sapply(ObjectsOfInterest, function(namedf){...}) I like this one for its

Re: [R] Reference variables by string in for loop

2011-04-29 Thread Michael Bach
Kenn Konstabel lebats...@gmail.com writes: Another way (not elegant but better and shorter than the eval-parse way) is to use get. ?get This one is handy for interactive use, thanks for the hint. Kind Regards, Michael Bach __ R-help@r-project.org