我有一个关于滚动连接的评论/问题
让 X,Y 为:
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)
在这里X
并按Y
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
从
执行Y[X, roll=-0.005]
让你
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)
所以我本来希望在最后一行得到更多的行,因为“mult”的默认行为是“all”,最后一行X
与5,6, may be 7
Y