I have two data.tables, and one has a subset of the rows / columns of the other. I would like to add the values ββof the smaller data.table to the values ββof the larger:
DT1 <- as.data.table(matrix(c(0, 1, 2, 3), nrow=2, ncol=2,
dimnames=list(c("a", "b"), c("a", "b"))), keep=T)
DT2 <- as.data.table(matrix(c(0, 0, 1, 2, 2, 1, 1, 0, 3), nrow=3, ncol=3,
dimnames=list(c("a", "b", "c"), c("a", "b", "c"))), keep=T)
DT1
DT2
I want to add DT1 to DT2 to get
I know that I can easily overwrite DT2 values ββwith DT1:
DT2[DT1, names(DT1) := DT1, on="rn"]
I was hoping something like this would work:
DT2[DT1, names(DT1) := DT1 + .SD, on="rn"]
... but it is not. There are probably some simple variations of this that will work, right?