Hi. this is my failed attempt at another question. How can I do regression inside a loop that changes the independent variable each time?

My lm statement is not assigning the independent variable. Thank you.

df <- data.frame(mtcars)

indepvars <- colnames(df[3:7])

summary <- data.frame()

for (i in 1:5){

model <- lm(mpg ~ indepvars[i], df)

summary[i,1] <- model$coefficients[1]

summary[i,2] <- model$coefficients[2]

}