Reputation: 169
I am using summary()
to create a, yes, summary from my regression. What now is printed is my variable names, including underscore.
Is there any way to change the printed variable names so that I can see e.g. "Age of dog" instead of dog_age
.
I can not change the variable names since they can not contain spaces.
Upvotes: 2
Views: 5153
Reputation: 99391
Something like this?
> x <- summary(lm(mpg ~ cyl+wt, mtcars))
> rownames(x$coef) <- c("YOUR", "NAMES", "HERE")
> x$coef
# Estimate Std. Error t value Pr(>|t|)
# YOUR 39.6863 1.7150 23.141 < 2e-16
# NAMES -1.5078 0.4147 -3.636 0.001064
# HERE -3.1910 0.7569 -4.216 0.000222
Or you could just change the names in the data before running regression
> names(mtcars)[1:3] <- rownames(x$coef)
> lm(YOUR ~ NAMES+HERE, mtcars)
# Call:
# lm(formula = YOUR ~ NAMES + HERE, data = mtcars)
# Coefficients:
# (Intercept) NAMES HERE
# 34.66099 -1.58728 -0.02058
Upvotes: 6
Reputation: 121618
You can use backtick
` to introduce spaces in variables:
dat = data.frame(`Age of dog`=1:10,`T`=1:10,check.names=FALSE)
summary(lm(T~`Age of dog`,data=dat))
Upvotes: 2