[R] How to translate string to variable inside a command in an easy way in R

UriB uriblass at gmail.com
Wed Jul 13 18:27:54 CEST 2011


Thanks
Here is another question 

I want to have a function that get a string for example
y="AMI" and make commands like the following

agg<-aggregate(numAMI ~MemberID,right.a,sum)

Note that I know that numAMI is part of right.a because another function
with the string AMI already generated it.

Is there a way to do it without paste parse and eval?

I can do it by the following commands for y="AMI"

numy<-paste("num",y,sep="")
texta<-paste("agg<-aggregate(",numy,sep="")
text2<-"~MemberID, right.a, sum)"
text1<-paste(texta,text2,sep="")
eval(parse(text=text1))

If you can have a shorter code for it then it can be productive.

--
View this message in context: http://r.789695.n4.nabble.com/How-to-translate-string-to-variable-inside-a-command-in-an-easy-way-in-R-tp3645594p3665462.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list