[R] question about formula for lm

Pedro Mardones mardones.p at gmail.com
Thu Jun 14 21:14:26 CEST 2007


Dear all;

Is there any way to make this to work?:

.x<-rnorm(50,10,3)
.y<-.x+rnorm(50,0,1)

X<-data.frame(.x,.y)
colnames(X)<-c("Xvar","Yvar")

Ytext<-"Yvar"

lm(Ytext~Xvar,data=X) # doesn't run

lm(Yvar~Xvar,data=X) # does run

The main idea is to use Ytext as input in a function, so you just type
"Yvar" and the model should fit....
Also, I need to avoid the expression X$Yvar~X$Xvar

Thanks for any idea

PM



More information about the R-help mailing list