Skip to contents

setleftjoin Fast left join for data.table that simply adds columns from r to l by reference. Requires that r has at most one item of each join group in order to be able to simply add to l.

Usage

setleftjoin(l, r, by = NULL)

Arguments

l

left side of the join (data.table)

r

right side of the join (data.table)

by

character vector for matching columns. Names, if they exist, refer to columns in the left table, values to columns in the right table

Value

a joined data.table, invisibly

Examples


library(data.table)
#> 
#> Attaching package: ‘data.table’
#> The following object is masked from ‘package:bit’:
#> 
#>     setattr

l <- data.table(a = c(1, 2, 3), b = c(3, 4, NA))
r <- data.table(b = c(3, 7, NA), c = c(1, 2, 4))

setleftjoin(l, r, by = "b")
#>        a     b     c
#>    <num> <num> <num>
#> 1:     1     3     1
#> 2:     2     4    NA
#> 3:     3    NA     4
setleftjoin(l, r, by = c("b" = "c"))
#>        a     b     c
#>    <num> <num> <num>
#> 1:     1    NA     1
#> 2:     2    NA    NA
#> 3:     3    NA     4