我之前问过这个问题,现在我想举个例子来说明为什么我会看到这种效果,希望能对你有所帮助:
require(data.table)
x <- data.table(a=1:10)
x[,a:=scale(a)]
# [,1]
# 1: -1.4863011
# 2: -1.1560120
# 3: -0.8257228
# 4: -0.4954337
# 5: -0.1651446
# 6: 0.1651446
# 7: 0.4954337
# 8: 0.8257228
# 9: 1.1560120
#10: 1.4863011
na.omit(x)
Error in `[.data.table`(object, !omit) :
i is invalid type (matrix). Perhaps in future a 2 column matrix could return a list of elements of DT (in the spirit of A[B] in FAQ 2.14). Please let datatable-help know if you'd like this, or add your comments to FR #1611.
原因似乎是
scale
不返回一个 vector
,而且 data.table
没有报错。 使用 x[,a:=as.vector(scale(a))]
可以解决这个问题。 我是否在文档中漏掉了什么?
data.table
的错误报告发布到错误的论坛。也许你应该将它发布到http://lists.r-forge.r-project.org/mailman/listinfo/datatable-help。 - Maiasaura