How does one retain labels in linear models? How to have the slope labelled Bar
or xBar
in the coefficient table below?
dat <- data.frame(
y = c(1:3, 10:12),
x = gl(2, 3, labels = c('Foo', 'Bar'))
)
coef(summary(mod <- lm(y ~ x, dat)))
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 6.5 0.4082483 15.92168 0.0000909619
# x1 -4.5 0.4082483 -11.02270 0.0003850677
Actual use case is more complicated, tens of linear models with tens of variables. I do realize that I could write my own function that both retrieves the labels and fits the model, but I wonder if I am missing something simpler.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…