Hello! So I am handling this problem with some arrays grp1-grp7, I want to write a loop to avoid tedious work, but I don't know how to transform string to boor? For example I used i=1 paste("grp",i, sep="") I only got "grp1" instead of grp1, which can't be manipulate using mean() or other function. I am not sure if I make myself clear... THANKS!!!! Nellie -- View this message in context: http://r.789695.n4.nabble.com/question-about-string-to-boor-tp3890983p3890983.html Sent from the R help mailing list archive at Nabble.com.
On Oct 10, 2011, at 12:52 PM, song_gpqg wrote:> Hello! > So I am handling this problem with some arrays grp1-grp7, I want to > write a > loop to avoid tedious work, but I don't know how to transform string > to > boor? > For example I used > i=1 > paste("grp",i, sep="")?get e.g. get( paste("grp",i, sep="") )> I only got "grp1" instead of grp1, which can't be manipulate using > mean() or > other function. > > I am not sure if I make myself clear... > THANKS!!!! > > Nellie > > > > -- > View this message in context: http://r.789695.n4.nabble.com/question-about-string-to-boor-tp3890983p3890983.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > 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.David Winsemius, MD West Hartford, CT
Hi Nellie, hope I got you right. I guess you want something like that. for (i in 1:7) { oneOfNelliesArray <- eval(parse(text=paste("grp",i, sep=""))) anyFunction(oneOfNelliesArray) } Paste() just returns you a string. But you want R to evaluate the expression. So you have to parse it and tell R to evaluate it. Christoph 2011/10/10 song_gpqg <song_gpqg@126.com>> Hello! > So I am handling this problem with some arrays grp1-grp7, I want to write a > loop to avoid tedious work, but I don't know how to transform string to > boor? > For example I used > i=1 > paste("grp",i, sep="") > I only got "grp1" instead of grp1, which can't be manipulate using mean() > or > other function. > > I am not sure if I make myself clear... > THANKS!!!! > > Nellie > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/question-about-string-to-boor-tp3890983p3890983.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > 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. >[[alternative HTML version deleted]]
On 11/10/11 08:21, Christoph Molnar wrote:> Hi Nellie, > > hope I got you right. I guess you want something like that. > > for (i in 1:7) { > oneOfNelliesArray<- eval(parse(text=paste("grp",i, sep=""))) > anyFunction(oneOfNelliesArray) > } > > Paste() just returns you a string. But you want R to evaluate the > expression. So you have to parse it and tell R to evaluate it.But using get() is so much simpler and safer. cheers, Rolf Turner