我想用 dcast.%ignore_a_1%
与 as.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
解决方案:
在当前CRAN版本的 data.table
,下面就可以了。
as.matrix(dcast.data.table(setDT(ChickWeight), weight ~ Diet,
value.var = "Time")[,-1])
本文来自投稿,不代表运维实战侠立场,如若转载,请注明出处:https://www.shizhanxia.com/3841.html