[Solved] how to use loop to do linear regression in R
If you really want to do this, it’s pretty trivial with lapply(), where we use it to “loop” over the other columns of df. A custom function takes each variable in turn as x and fits a model for that covariate. df <- data.frame(crim = rnorm(20), rm = rnorm(20), ad = rnorm(20), wd = rnorm(20)) … Read more