Left and right joins

การ Join ข้อมูลด้วย data.table ใน R

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

Left joins

เพิ่มข้อมูล จาก data.table ขวา ไปยัง data.table ซ้าย

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

การ Join ข้อมูลด้วย data.table ใน R

Right joins

เพิ่มข้อมูล จาก data.table ซ้าย ไปยัง data.table ขวา

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

การ Join ข้อมูลด้วย data.table ใน R

Right joins - Left joins

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

# Same as
merge(x = shipping, y = demographics, by = "name", all.x = TRUE)
การ Join ข้อมูลด้วย data.table ใน R

ค่าดีฟอลต์

  • ค่าดีฟอลต์ของ all, all.x และ all.y คือ FALSE ในฟังก์ชัน merge()

  • ดูค่าดีฟอลต์ของอาร์กิวเมนต์ได้ด้วย help("merge")

การ Join ข้อมูลด้วย data.table ใน R

คำแนะนำแบบฝึกหัด

Left join shipping กับ demographics:

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

Right join shipping กับ demographics:

merge(demographics, shipping, by = "name", all.y = TRUE)
การ Join ข้อมูลด้วย data.table ใน R

มาฝึกกันเถอะ!

การ Join ข้อมูลด้วย data.table ใน R

Preparing Video For Download...