左连接与右连接

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

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

左连接

将右侧 data.table 的信息添加到左侧 data.table

merge(x = demographics, y = shipping, by = "name", all.x = TRUE)

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

右连接

将左侧 data.table 的信息添加到右侧 data.table

merge(x = demographics, y = shipping, by = "name", all.y = TRUE)

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

右连接 - 左连接

# 右连接
merge(x = demographics, y = shipping, by = "name", all.y = TRUE)

# 等同于
merge(x = shipping, y = demographics, by = "name", all.x = TRUE)
在 R 中使用 data.table 进行数据表连接

默认值

  • merge() 中,allall.xall.y 的默认值均为 FALSE

  • 可用 help("merge") 查看参数默认值

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

练习说明

shipping 左连接到 demographics

merge(demographics, shipping, by = "name", all.x = TRUE)

shipping 右连接到 demographics

merge(demographics, shipping, by = "name", all.y = TRUE)
在 R 中使用 data.table 进行数据表连接

Passons à la pratique !

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

Preparing Video For Download...