Skip to content
Prev 295457 / 398506 Next

Get variable names from results of lm()

Hi Marc,

Just to point out some difference,


?x <- 1:20
? y <-? x + (x/4 - 2)^3 + rnorm(20, sd=3)
????? names(y) <- paste("O",x,sep=".")
?????? ww <- rep(1,20); ww[13] <- 0
????? summary(lmxy <- lm(y ~ x + I(x^2)+I(x^3) + I((x-10)^2),
????????????????????????? weights = ww), cor = TRUE)
[1] "y" "x"
[1] "(Intercept)" "x"?????????? "I(x^2)"????? "I(x^3)"?? 



A.K.

----- Original Message -----
From: Marc Schwartz <marc_schwartz at me.com>
To: Peter Ehlers <ehlers at ucalgary.ca>
Cc: "r-help at r-project.org" <r-help at r-project.org>; jdub <jack at ramas.com>
Sent: Wednesday, May 23, 2012 3:12 PM
Subject: Re: [R] Get variable names from results of lm()
On May 23, 2012, at 1:42 PM, Peter Ehlers wrote:

            
Just to throw out another solution here, the function ?all.vars is helpful:

LM <- lm(Petal.Length ~ ., data = iris)
Petal.Length ~ Sepal.Length + Sepal.Width + Petal.Width + Species
[1] "Petal.Length" "Sepal.Length" "Sepal.Width"? "Petal.Width" 
[5] "Species"? 


Regards,

Marc Schwartz
______________________________________________
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.