left_roll: Left or right rolling join

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/left_roll.R

Description

Perform rolling join

Usage

1
left_roll(x, y, on, roll, ...)

Arguments

x,

y data.table

on

character vector of join columns. The last is the join column

roll

direction and allowed size of the roll. see ?data.table.

...

additional arguments passed to setprefix (unimplemented)

Details

It is best to think of x as the m

Duplicated y's

  1. It is often expected that nrow(results) equals nrow(x). This is not true when are duplicated rows in y; it maybe important to the application to dedupe the rows of y before joining?

  2. When deduping y, ensure that you are taking the correct duplicate. 'unique“ retains the first occerence.

Value

a data.table object with

Note

Author(s)

Decision Patterns

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
set.seed(1)
x <- data.table(
         letter=sample(letters[1:2],10, replace=TRUE)
       , year_x=sample( 2000:2010, 10, replace=TRUE )
     )
x <- x[ order(letter, year_x) ]
#' x <- unique(x)

y <- data.table(
         letter=sample(letters[1:2],5, replace=TRUE)
       , year_y=sample( 2000:2010, 5, replace=TRUE )
     )
y <- y[ order(letter, year_y) ]
y <- unique(y)
y

# on=c('letter','year')
on=c('letter',year_x='year_y')
roll=Inf


ret <- left_roll(x,y,on=on,roll=roll)
ret[ letter=="a"]; x[letter=="a"]; y[ letter=="a"]
ret[ letter=="b"]; x[letter=="b"]; y[ letter=="b"]

decisionpatterns/data.table.plus documentation built on June 15, 2020, 10:26 p.m.