I have two data.tables, and one has a subset of rows/columns of another. I'd like to increment values of the larger data.table by 1 for every non-zero value in smaller table:
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
# rn a b
#1: a 0 2
#2: b 1 3
DT2
# rn a b c
#1: a 0 2 1
#2: b 0 2 0
#3: c 1 1 3
I'd like to increment values in DT2 so that I get
# rn a b c
#1: a 0 3 1
#2: b 1 3 0
#3: c 1 1 3
(This is similar to my previous question on adding DT1 and DT2: Adding values in two data.tables... I need to do both :) )