I have written the following code. I am extremely new to R. I don't have the knowledge of the language to debug this.
library(MASS)
RegressOnAll <- function() {
li = list()
nms = names(Boston)
for (i in 2:length(nms)) {
li[[i]] = lm(crim ~ nms[i], data=Boston)
}
}
RegressOnAll()
An error message from the terminal
Error in model.frame.default(formula = crim ~ nms[i], data = Boston, drop.unused.levels = TRUE) :
variable lengths differ (found for 'nms[i]')
Calls: RegressOnAll ... lm -> eval -> eval -> <Anonymous> -> model.frame.default
Execution halted
I am not sure what to do with this error.
My goal is to pick out regression coefficients and compare them with multiple regression coefficients.