[R] Extracting original variable list from lm object

Sung, Iyue Iyue.Sung at lippincott.com
Tue Feb 19 19:10:42 CET 2008


Fellow R users,

I have an lm object, from which I would like to extract the list of
original variables.
The problem I have is the formula includes functions of the covariates.

I tried using "attr", but the result stores the transformed variable
name.  For example:

> my.model<-lm(y ~ a + log(b + 1), data=my.data)
> as.character(attr(my.model$terms, "variables"))[-1]
 [1] "y" "a" "log(b + 1)"

But I just want a character vector of the original variables ("y", "a",
"b"), not ("y", "a", "log(b + 1)").
Does someone have a solution they could kindly share?

Thanks,
Iyue
---------------------------------------------------------------------------- 
This e-mail and any attachments may be confidential or l...{{dropped:11}}



More information about the R-help mailing list