[R] Get variable names from results of lm()

R. Michael Weylandt michael.weylandt at gmail.com
Wed May 23 18:55:16 CEST 2012


I think the easiest that comes to mind is simply

names(coef(myMod))

But did you look at myMod$terms[[3]] ? That seems to be the RHS of the
formula input (in the few cases I tried)

Best,
Michael

On Wed, May 23, 2012 at 10:58 AM, jdub <jack at ramas.com> wrote:
>
> 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