R で学ぶ data.table によるデータ結合
Scott Ritchie
Postdoctoral Researcher in Systems Genomics
data.table 構文の基本形
DT[i, j, by]
| | |
| | --> グループ化の基準
| -----> 実行する処理
--------> 対象の行
data.table 構文による結合の基本形
DT[i, on]
| |
| ----> 結合キー列
--------> 結合先の data.table
デフォルトの結合は右結合です
demographics[shipping, on = .(name)]

list() または .() 内の変数は、両方の data.table の列名で参照されます
shipping[demographics, on = list(name)]
shipping[demographics, on = .(name)]
文字ベクトルも使用できます
join_key <- c("name")
shipping[demographics, on = join_key]
左結合は、順序を入れ替えた右結合と同じです:
shipping[demographics, on = .(name)]

nomatch = 0 を設定して内部結合を実行します:
shipping[demographics, on = .(name), nomatch = 0]

data.table 構文では対応していません。merge() 関数を使用してください:
merge(demographics, shipping, by = "name", all = TRUE)

別の data.table に一致しない行に data.table をフィルタリングします
demographics[!shipping, on = .(name)]

R で学ぶ data.table によるデータ結合