[R] Get variable names from results of lm()
arun
smartpink111 at yahoo.com
Wed May 23 18:47:48 CEST 2012
Hi,
I assume this is what you are looking.
?variable.names()
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)
variable.names(lmxy)
[1] "(Intercept)" "x" "I(x^2)" "I(x^3)"
A.K.
----- Original Message -----
From: jdub <jack at ramas.com>
To: r-help at r-project.org
Cc:
Sent: Wednesday, May 23, 2012 10:58 AM
Subject: [R] Get variable names from results of lm()
What is the best way to get the variable names used in lm() from its
results?
Stumbling around I found I could get the response variable name from
myMod$terms[[2]]
but using
myMod$terms[[1 ]]
gives a tilda.
I found the names buried in other places in the model object and in the
summary of the model, but is there a more direct way, similar to using
coef(myMod) to get the coefficients?
--
View this message in context: http://r.789695.n4.nabble.com/Get-variable-names-from-results-of-lm-tp4631095.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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