ฟังก์ชัน merge

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

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

Joins

  • แนวคิดของ join มาจากภาษาคิวรีฐานข้อมูล (เช่น SQL)

  • join มาตรฐาน 4 ประเภท:

    • inner
    • full
    • left
    • right
  • ทำได้ทั้งหมดด้วย merge()

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

Inner join

เก็บเฉพาะข้อมูลที่มีใน data.table ทั้งสอง

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

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

อาร์กิวเมนต์ by

ใช้ by เพื่อหลีกเลี่ยงการพิมพ์ชื่อคอลัมน์ซ้ำ

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

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

Full join

เก็บข้อมูลทุกแถวที่มีอยู่ใน data.table ใดก็ได้

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

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

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

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

Preparing Video For Download...