[R] vaiable in lm

Ivan Calandra ivan.calandra at uni-hamburg.de
Fri May 21 10:41:31 CEST 2010


Hi!

The problem is that paste() returns a character string.
You can use get() this way:
lm(y ~ get(paste("aa",1,sep="_")), data = tmp)

Or:
lm(tmp[[2]]~tmp[[1]], data=tmp)

HTH,
Ivan


Le 5/21/2010 09:54, Yuan Jian a écrit :
> 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)
> 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.
>
>    

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php



More information about the R-help mailing list