Skip to content
Prev 295453 / 398506 Next

Get variable names from results of lm()

On 2012-05-23 09:55, R. Michael Weylandt wrote:
It depends a bit on just what the OP wants. In case one of the
predictors is a factor, say 'grp' with levels c('A','B','C'), the
coefs will include the names 'grpB' and 'grpC'. If only the
name 'grp' is wanted, one could use myMod$terms[[3]] or
equivalently formula(myMod)[[3]]. It might be instructive for the
OP to look at as.list(formula(myMod)). formula(myMod) is a
language object which has the tilde operator operate on
the LHS (component 2) and the RHS (component 3).

Peter Ehlers