join.on: Function that encapsulates common pre- and post- join...

Description Usage Arguments Value Examples

View source: R/join.on.R

Description

Function that encapsulates common pre- and post- join operations with data tables. Data table 2 is joined to data table 1 on keys that do not need to have the exact same names. The user can optionally specify which columns from data table 2 are joined to data table 1 and those columns can be optionally prefixed in the result.

Usage

1
join.on(dt1,dt2,keys1,keys2=NULL,include.from.dt2=NULL,included.prefix='')

Arguments

dt1

The first data table in the join, all columns and rows from dt1 will be present in the result with columns from dt2 added where keys match.

dt2

The second data table in the join, dt2 should be seens as contributing data to the rows of dt1.

keys1

The columns form dt1 to use as keys in the join.

keys2

The columns form dt2 to use as keys in the join. Leave as NULL if the keys from dt2 are identical to keys1.

include.from.dt2

The columns from dt2 to add to dt1. Leave as NULL to include all columns.

included.prefix

Optional prefix to append to the columns from dt2 that are added to dt1.

Value

A data table is the result of joining specified columns from dt2 to dt1.

Examples

1
2
3
4
A <- data.table(a=1:10,b=LETTERS[1:10],key='a')
B <- data.table(c=1:20,d=letters[1:20],e=101:120,f=131:150,key='c')

join.on(A,B,key1='a',keys2='c',include.from.dt2=c('d','f'),included.prefix='from.b.') # note that we join

colinsheppard/colinmisc documentation built on July 10, 2020, 5:59 p.m.