当我运行此代码时:
# Create example data
df <- tibble(age=rnorm(10),
income=rnorm(10))
make_model <- function(response_var, df){
# Create formula
form <- as.formula(response_var ~ .)
# Create model
model <- lm(form , data=df)
# Return coefficients
return(coef(model))
}
make_model(income, df)
我收到以下错误
Error in eval(predvars, data, env) : object 'income' not found
如何使用 quasiquotation 使此功能起作用?我假设逻辑与我们如何调用library(dplyr)
而不是library("dplyr")
.