Description Usage Arguments Details Value Note Author(s) See Also Examples
Perform rolling join
1 |
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 |
It is best to think of x as the m
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?
When deduping y, ensure that you are taking the correct duplicate. 'unique“ retains the first occerence.
a data.table object with
The name roll
comes from the data.table/ts rolling joins
zip
is also an interesting name – zipping on a fields with
roll
telling what to do first
Decision Patterns
setprefix
dplyr::left_join()
data.table::[.data.table
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"]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.