Rolling joins: roll forwards and backwards

前端 未结 2 722
一生所求
一生所求 2021-02-19 01:18

data.table is awesome, because I can do rolling joins, and even do rolling joins within groups!

library(data.table)
set.seed(42)
metrics &l         


        
相关标签:
2条回答
  • 2021-02-19 01:51

    This is possible in data.table version 1.8.8 released March 2013:

    metrics[calendar, roll=TRUE, rollends=c(TRUE, TRUE)]
    

    From the data.table NEWS file:

    In addition to TRUE/FALSE, 'roll' may now be a positive number (roll forwards/LOCF) or negative number (roll backwards/NOCB). A finite number limits the distance a value is rolled (limited staleness). roll=TRUE and roll=+Inf are equivalent. 'rollends' is a new parameter holding two logicals. The first observation is rolled backwards if the first value of rollends is TRUE. The last observation is rolled forwards if the second value of rollends is TRUE. If roll is a finite number, the same limit applies to the ends. New value roll='nearest' joins to the nearest value (either backwards or forwards) when the value falls in a gap, and to the end value according to 'rollends'. 'rolltolast' has been deprecated. For backwards compatibility it is converted to {roll=TRUE;rollends=c(FALSE,FALSE)}.

    As always, to download the most up-to-date version of data.table, see Installation.

    0 讨论(0)
  • 2021-02-19 02:01

    metrics[calendar, roll = TRUE, rollends = c(TRUE, TRUE)]

    0 讨论(0)
提交回复
热议问题