I have a list with the values called out which looks like this:
["test ~ x1", "test ~ x2" "test ~ x3" "test ~ x4"]
I want to use every value in this list in a lm-function. So I tried to a foreach.
foreach(i = 1:4) %do% lm(out[i], data = test_data)
But this does not work. Do you Guys have any idea?
Store it in a vector and use lapply :
lapply
out <- c("test ~ x1", "test ~ x2", "test ~ x3", "test ~ x4") result <- lapply(out, function(x) lm(x, data = test_data))
2.1m questions
2.1m answers
60 comments
57.0k users