Re: [R] vaiable in lm

2010-05-21 Thread Gabor Grothendieck
Try this: lm(y ~., tmp) On Fri, May 21, 2010 at 3:54 AM, 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

Re: [R] vaiable in lm

2010-05-21 Thread Ivan Calandra
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 eas

Re: [R] vaiable in lm

2010-05-21 Thread Uwe Ligges
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 ~ pas

[R] vaiable in lm

2010-05-21 Thread Yuan Jian
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