[R] how to seperate " "? or how to do regression on each variable when I have multiple variables?
Soyeon Kim
yunni0731 at gmail.com
Mon Sep 20 19:03:17 CEST 2010
Dear All,
I have data which contains 14 variables. And I have to regress one of
variables on each variable (simple 13 linear regressions)
I try to make a loop and store only R-squared
colnames(boston)
[1] "CRIM" "ZN" "INDUS" "CHAS" "NOX" "RM" "AGE"
[8] "DIS" "RAD" "TAX" "PTRATIO" "B" "LSTAT" "MEDV"
name <- colnames(boston)
r <- rep(0, 13)
for(i in 1: 13) {
r[i] <- summary(lm(MEDV ~ name[i], data = boston))$r.squared
}
but this doesn't work because name have " " for each variable. How to
remove " " for name of each variable?
Or do you know the way I can do regression MEDV on each variable?
Thank you ahead,
Soyeon
More information about the R-help
mailing list