[R] Re-assigning variables stored as character strings in another variable
Henrique Dallazuanna
wwwhsd at gmail.com
Mon Feb 22 20:58:07 CET 2010
See ?get and ?assign
On Mon, Feb 22, 2010 at 4:49 PM, Anthony Damico <ajdamico at gmail.com> wrote:
> Is there any way to get the last line of this code to double the contents of
> a and b without naming them directly?
>
> #create variables a and b
> a<-5
> b<-10
>
> #store variable names a and b in variables c and d
> c<-"a"
> d<-"b"
>
> e<-c(c,d)
>
> #loop through both variables
> for (i in e){
>
> #print the numbers five and ten using only the variables c and d
> #this line works fine
> print(eval(parse(text=i)))*2
>
> #re-assign variables a and b using only variables c and d
> #this line does not work -
> parse(text=i) <- eval(parse(text=i))*2
> }
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list