Left và right join

Kết hợp dữ liệu với data.table trong R

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

Left join

Thêm thông tin từ data.table bên phải vào data.table bên trái

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

Kết hợp dữ liệu với data.table trong R

Right join

Thêm thông tin từ data.table bên trái vào data.table bên phải

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

Kết hợp dữ liệu với data.table trong R

Right join - Left join

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

# Tương đương với
merge(x = shipping, y = demographics, by = "name", all.x = TRUE)
Kết hợp dữ liệu với data.table trong R

Giá trị mặc định

  • Giá trị mặc định của all, all.x và all.y là FALSE trong hàm merge()

  • Tra cứu giá trị mặc định của đối số bằng help("merge")

Kết hợp dữ liệu với data.table trong R

Hướng dẫn bài tập

Left join shipping vào demographics:

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

Right join shipping vào demographics:

merge(demographics, shipping, by = "name", all.y = TRUE)
Kết hợp dữ liệu với data.table trong R

Cùng luyện tập nào!

Kết hợp dữ liệu với data.table trong R

Preparing Video For Download...