Hi,

Change:
aa$z<-  eval(parse(text=bb))

 aa
#  x y  z
#1 2 3  3
#2 4 5  7
#3 6 7 11
A.K.

I want to create a new column to a data frame using a formula from another 
variable: 
Example: 
I have a data set "aa" is; 
x    y 
2    3 
4    5 
6    7 

My R code is; 
>bb <- "x+y-2" 
>attach(aa) 
>aa$z<- bb 
>detach(aa) 

the result is; 
x  y  z 
2  3  x+y-2 
4  5  x+y-2 
6  7  x+y-2 

but I want like; 
x  y  z 
2  3  3 
4  5  7 
6  7  11 

Could you please help me..

______________________________________________
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.

Reply via email to