处理大量变量并使用构造公式来处理它们(通过paste0()
)使用传递给函数的变量。我偶然发现了一个我无法弄清楚的问题/错误。用一个玩具示例最简单地解释:
library(mice)
imp2 = mice(nhanes)
# So both these models run fine:
mod1 <- glm(bmi ~ hyp + age, data=nhanes)
mod1.im <- with(imp2, glm(bmi ~ hyp + age))
# However if I try to pass a formula to glm() in the with() I get an error
formula = bmi ~ hyp + age
mod2 <- glm(formula, data=nhanes)
mod2 <- with(imp2, glm(formula))
#Running the above leads to the following error:
> mod2 <- with(imp2, glm(formula))
Error in eval(expr, envir, enclos) : object 'bmi' not found
我该如何解决这个问题?为什么找不到 BMI?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)