akrun borrowed my answer that night, now I (partially) occupy it.
do.call places the variables in the call output so that it do.call correctly. Here's a common feature for simple regression.
doModel <- function(col1, col2, data = hsb2, FUNC = "lm") { form <- as.formula(paste(col1, "~", col2)) do.call(FUNC, list(form, substitute(data))) } lapply(varlist, doModel, col1 = "read")
Note. As stated in his comment
sapply(varlist, doModel, col1 = "read", simplify = FALSE)
saves the names in a list, and also resolves a subset of list$name .
source share