The main problem is described in the title of the question. We go straight to the example below.
I have two data sets:
library(data.table) dt1 <- data.table(date = as.Date("2015-06-28")+c(0L,3L,5L,7L), key="date") dt2 <- data.table(date = as.Date("2015-06-30")+c(0:1,4L), val = letters[7:9], dummy = rep(NA,3), key="date")
I want the val column from dt2 added to dt1 using a sliding join.
The following statement will produce similar output for the expected:
dt2[dt1, roll=TRUE] # date val dummy # 1: 2015-06-28 NA NA # 2: 2015-07-01 h NA # 3: 2015-07-03 h NA # 4: 2015-07-05 i NA
These are two problems with this statement:
1. I did not want to have a dummy column 2. I want to do this from the link:
address(dt1) # [1] "0x3b57540" address(dt2[dt1, roll=TRUE]) # [1] "0x3b4e1f0"
So, I'm looking for a rolling connection and add a column by reference for my dt1 and dt2 , the expected results:
# date val
And, of course, address(dt1) must match the address magic statement.
source share