【发布时间】:2017-05-31 13:33:46
【问题描述】:
尝试使用此循环在所有数字行中估算缺失值:
for(i in 1:ncol(df)){
if (is.numeric(df[,i])){
df[is.na(df[,i]), i] <- mean(df[,i], na.rm = TRUE)
}
}
如果未附加 data.table 包,则上面的代码可以正常工作。一旦我附加了 data.table 包,行为就会改变,它会向我显示错误:
Error in `[.data.table`(df, , i) :
j (the 2nd argument inside [...]) is a single symbol but column name 'i'
is not found. Perhaps you intended DT[,..i] or DT[,i,with=FALSE]. This
difference to data.frame is deliberate and explained in FAQ 1.1.
我到处尝试了“..i”和“with=FALSE”,但没有成功。实际上它甚至没有通过第一个 is.numeric 条件。
【问题讨论】:
标签: r data.table