[R] vaiable in lm

Uwe Ligges ligges at statistik.tu-dortmund.de
Fri May 21 10:28:11 CEST 2010



On 21.05.2010 09:54, Yuan Jian wrote:
> Hi,
>
> if I know the colnames x and y in the following example, I can easily to do lm.
> tmp<- data.frame(x=c(1,1.2),y=c(1,2))
> lm(y ~ x, data=tmp)
>
> when the colnames are variable, what should I do? for example
> colnames(tmp)[1]<- paste("aa",1,sep="_")
> lm(y ~ paste("aa",1,sep="_"), data = tmp)


myformula <- formula(paste("y ~", paste("aa", 1, sep="_")))
lm(myformula, data = tmp)


Uwe Ligges



> it gives me error.
>
>
>
>
>
>
> 	[[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.



More information about the R-help mailing list