Re: [R] Extracting original variable list from lm object

From: Sung, Iyue <Iyue.Sung_at_lippincott.com>
Date: Tue, 19 Feb 2008 13:28:21 -0500

perfect. many thanks.

-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck_at_gmail.com] Sent: Tuesday, February 19, 2008 1:26 PM To: Sung, Iyue
Cc: r-help_at_r-project.org
Subject: Re: [R] Extracting original variable list from lm object

Try:

all.vars(formula(my.model))

On Feb 19, 2008 1:10 PM, Sung, Iyue <Iyue.Sung_at_lippincott.com> wrote:
> 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}}
>
> ______________________________________________
> 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.
>




This e-mail and any attachments may be confidential or l...{{dropped:24}}

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. Received on Tue 19 Feb 2008 - 18:35:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Feb 2008 - 19:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive