在 R 中使用 data.table 进行数据表连接
Scott Ritchie
Postdoctoral Researcher in Systems Genomics
连接(join)概念源自数据库查询语言(如 SQL)。
四种常见连接:
以上四种都可用 merge() 实现
仅保留在两个 data.table 中都有信息的观测值
merge(x = demographics, y = shipping,
by.x = "name", by.y = "name")

使用 by 避免重复输入相同的列名
merge(x = demographics, y = shipping,
by = "name")

保留任一 data.table 中的所有观测值
merge(x = demographics, y = shipping,
by = "name", all = TRUE)

在 R 中使用 data.table 进行数据表连接