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
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
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
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
4 matches
Mail list logo