【发布时间】:2021-06-26 00:42:46
【问题描述】:
我正在尝试遍历我的数据表列并使用 for 循环将 glm 应用于每一列。
for(n in 1:ncol(dt)){
model = glm(y ~ dt[, n], family=binomial(link="logit"))
}
为什么这不起作用?我收到此错误:
Error in `[.data.table`(dt, , n) :
j (the 2nd argument inside [...]) is a single symbol but column name 'n' is not found. Perhaps you intended DT[, ..n]. This difference to data.frame is deliberate and explained in FAQ 1.1.
我几乎设法使用dt[[n]] 之类的东西使它工作,但我认为它摆脱了列名。
【问题讨论】:
标签: r for-loop data.table