我想将矩阵分配给 a 的多列子集,data.table
但矩阵最终被视为列向量。例如,
dt1 <- data.table(a1=rnorm(5), a2=rnorm(5), a3=rnorm(5))
m1 <- matrix(rnorm(10), ncol=2)
dt1[,c("a1","a2")] <- m1
Warning messages:
1: In `[<-.data.table`(`*tmp*`, , c("a1", "a2"), value = c(-0.308851784175091, :
2 column matrix RHS of := will be treated as one vector
2: In `[<-.data.table`(`*tmp*`, , c("a1", "a2"), value = c(-0.308851784175091, :
Supplied 10 items to be assigned to 5 items of column 'a1' (5 unused)
3: In `[<-.data.table`(`*tmp*`, , c("a1", "a2"), value = c(-0.308851784175091, :
2 column matrix RHS of := will be treated as one vector
4: In `[<-.data.table`(`*tmp*`, , c("a1", "a2"), value = c(-0.308851784175091, :
Supplied 10 items to be assigned to 5 items of column 'a2' (5 unused)
这个问题可以通过首先转换m1
为另一个data.table
对象来解决,但我很好奇这个错误的原因是什么。dt1
如果是data.frame
;则上述语法将起作用 不使用它的架构原理是什么data.table
?