Roll data.table with rollers

I am having trouble working roll=-Inf while defining rollends=FALSE . If rollends not installed or not set to TRUE , I see the expected result. I would be grateful for any suggestions.

 library(data.table) dt1 = data.table(Date=seq(from=as.Date("2013-01-03"), to=as.Date("2013-06-27"), by="1 week"), key="Date")[, ind:=.I] dt2 = data.table(Date=seq(from=as.Date("2013-01-01"), to=as.Date("2013-06-30"), by="1 day"), key="Date") 

I expect to see that 2013-01-05 and 2013-06-26 filled in the output below.

 dt1[dt2, roll=-Inf, rollends=FALSE] Date ind 1: 2013-01-01 NA 2: 2013-01-02 NA 3: 2013-01-03 1 4: 2013-01-04 2 5: 2013-01-05 NA --- 177: 2013-06-26 NA 178: 2013-06-27 26 179: 2013-06-28 NA 180: 2013-06-29 NA 181: 2013-06-30 NA 

This works as expected, the data ind rolls forward, but not beyond the endpoints defined in dt1 data.table .

 dt1[dt2, roll=-Inf] Date ind 1: 2013-01-01 1 2: 2013-01-02 1 3: 2013-01-03 1 4: 2013-01-04 2 5: 2013-01-05 2 --- 177: 2013-06-26 26 178: 2013-06-27 26 179: 2013-06-28 NA 180: 2013-06-29 NA 181: 2013-06-30 NA 
+6
source share
1 answer

You're right. It looks like an error.

UPDATE : now fixed in v1.8.11 (commit 980). From NEWS :

X[Y,roll=-Inf,rollends=FALSE] did not scan the middle correctly if the Y key was entered. It was normal if Y was not turned on or rollends left as the default [ c(TRUE,FALSE) when roll<0 ]. Thanks to user338714 for reporting. Added tests.

Thanks for the great question!

+6
source

Source: https://habr.com/ru/post/954511/


All Articles