data.table 的矩阵运算,规格不正确?

Matrix operation with data.table, incorrect specification?

我想将 dcast.data.tableas.matrix 一起使用,就像我将它与 dcast 一起使用一样,但我未能获得可比较的结果。如果有任何建议,我将不胜感激。

library(reshape2)
library(data.table)
data(ChickWeight)

# this returns the correct dimension:
> as.matrix(dcast(ChickWeight, weight ~ Diet, value.var = "Time")[,-1])
Aggregation function missing: defaulting to length
        1 2 3 4
  [1,]  1 0 0 0
  [2,]  2 3 2 1
  [3,]  1 2 0 2
      .....

# this doesn't
    > as.matrix(dcast.data.table(setDT(ChickWeight), weight ~ Diet, value.var = "Time")[,-1])
Aggregate function missing, defaulting to 'length'
     [,1]
[1,]   -1

data.table 的当前 CRAN 版本中,以下是可以的:

as.matrix(dcast.data.table(setDT(ChickWeight), weight ~ Diet, 
                      value.var = "Time")[,-1])