循环列表R中的多个GLM对象的变量列表
我的一生无法理解为什么在R :(
## Unadjusted model
noadj_var <- list("a",
"b",
"c",
"d",
)
for (i in 1:length(noadj_var)) {
paste0("unadjusted_model_",i) <- glm(
df$dependent_variable ~ i,
data = df[df$present_2018 == "Yes" , ],
family = binomial(link=logit),
na.action = na.exclude
)
}
我有错误:
Error in model.frame.default(formula = df$dependent_variable ~ i, data = df[df$present_2018 == :
variable lengths differ (found for 'i')
我不明白为什么我有na.Action = Na.exclude时
会出现 是搞砸了吗?
此错误那 。
I can not for the life of me see why this isn't working for me in R:(
## Unadjusted model
noadj_var <- list("a",
"b",
"c",
"d",
)
for (i in 1:length(noadj_var)) {
paste0("unadjusted_model_",i) <- glm(
df$dependent_variable ~ i,
data = df[df$present_2018 == "Yes" , ],
family = binomial(link=logit),
na.action = na.exclude
)
}
I get the error:
Error in model.frame.default(formula = df$dependent_variable ~ i, data = df[df$present_2018 == :
variable lengths differ (found for 'i')
I don't understand why I get this error when I have na.action = na.exclude
Is there something else that is being messed up?
Just to preface this the variable names "a", "b", "c" are not the real names, and I can't just change them to a sequence, it needs to be a list of strings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
purrr
软件包的另一种可能性:Another possibility with the
purrr
package: