I have a remark/question about rolling joins
Let X,Y be:
set.seed(123);
X <- data.table(x=c(1,1,1,2,2),y=c(T,T,F,F,F),t=as.POSIXct("08:00:00.000",format="%H:%M:%OS")+sample(0:999,5,TRUE)/1e3)
Y <- copy(X)
set.seed(123)
Y[,`:=`(IDX=.I,t=t+sample(c(-5:5)/1e3,5,T))]
Y <- rbindlist(list(Y, X[5,][,IDX:=6][,t:=t+0.001], X[5,][,IDX:=7][,t:=t+0.002]))
setkey(X,x,y,t)
setkey(Y,x,y,t)
here X
and Y
are sorted by x,y,t
R) X
x y t
1: 1 FALSE 2013-06-20 08:00:00.407
2: 1 TRUE 2013-06-20 08:00:00.286
3: 1 TRUE 2013-06-20 08:00:00.788
4: 2 FALSE 2013-06-20 08:00:00.882
5: 2 FALSE 2013-06-20 08:00:00.940
R) Y
x y t IDX
1: 1 FALSE 2013-06-20 08:00:00.407 3
2: 1 TRUE 2013-06-20 08:00:00.284 1
3: 1 TRUE 2013-06-20 08:00:00.791 2
4: 2 FALSE 2013-06-20 08:00:00.886 4
5: 2 FALSE 2013-06-20 08:00:00.940 6
6: 2 FALSE 2013-06-20 08:00:00.942 7
7: 2 FALSE 2013-06-20 08:00:00.945 5
From
executing Y[X, roll=-0.005]
gets you
R) Y[X, roll=-0.005]
x y t IDX
1: 1 FALSE 2013-06-20 08:00:00.407 NA => due to precision the roll is no match
2: 1 TRUE 2013-06-20 08:00:00.286 NA => ok
3: 1 TRUE 2013-06-20 08:00:00.788 2 => ok (x,y) matched and 788-791=-3
4: 2 FALSE 2013-06-20 08:00:00.882 4 => same
5: 2 FALSE 2013-06-20 08:00:00.940 6 => NOT AN EXACT MATCH (precision)
So I would have expected to get more lines FOR THE LAST LINE as the default behaviour of "mult" is "all" and the last line of X
is matched by lines 5,6, may be 7
of Y
d = data.table(a = c(1.0,2.0,2.0), by = c(1:3), key = 'a'); d[J(2.1), ...]
, because this one is very hard to understand) – eddi