I'm having trouble getting roll=-Inf
to work when defining rollends=FALSE
. When rollends
is not set or set to TRUE
, I see the expected result. I would appreciate 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 would expect to see 2013-01-05
and 2013-06-26
populated 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 is working as expected, the ind
data is rolled forward but not outside of the endpoints defined in the 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
You're right. This looks like a bug.
UPDATE : Now fixed in v1.8.11 (commit 980). From NEWS :
X[Y,roll=-Inf,rollends=FALSE]
didn't roll the middle correctly ifY
was keyed. It was ok ifY
was unkeyed orrollends
left as the default [c(TRUE,FALSE)
whenroll<0
]. Thanks to user338714 for reporting. Tests added.
Thanks for the great question!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With