I would like to assign a multi-column subset of data.table to the matrix, but the matrix ends up being treated as a column vector. For example,
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)
The problem can be solved by first converting m1 to another data.table object, but I'm curious what are the reasons for this error. The above syntax will work if dt1 was data.frame ; What is the architectural rationale for not working with data.table ?
r data.table
Abiel Nov 12 '13 at 0:51 2013-11-12 00:51
source share