Set operations

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

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

ฟังก์ชัน Set operation

เมื่อมี data.tables สองตารางที่มีคอลัมน์เหมือนกัน:

  • fintersect(): แถวใดที่ data.tables ทั้งสองมีร่วมกัน?
  • funion(): แถวที่ไม่ซ้ำกันทั้งหมดจาก data.tables ทั้งสองมีอะไรบ้าง?

  • fsetdiff(): แถวใดที่มีเฉพาะใน data.table นี้?

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

Set operations: `fintersect()`

ดึงแถวที่ปรากฏใน data.tables ทั้งสองตาราง

fintersect(dt1, dt2)

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

`fintersect()` และแถวที่ซ้ำกัน

แถวที่ซ้ำกันจะถูกละเว้นโดยค่าเริ่มต้น:

fintersect(dt1, dt2)

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

`fintersect()` และแถวที่ซ้ำกัน

all = TRUE: เก็บจำนวนสำเนาที่ปรากฏในทั้งสอง data.tables:

fintersect(dt1, dt2, all = TRUE)

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

Set operations: `fsetdiff()`

ดึงแถวที่มีเฉพาะใน data.table แรก

fsetdiff(dt1, dt2)

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

`fsetdiff()` และแถวที่ซ้ำกัน

แถวที่ซ้ำกันจะถูกละเว้นโดยค่าเริ่มต้น:

fsetdiff(dt1, dt2)

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

`fsetdiff()` และแถวที่ซ้ำกัน

all = TRUE: คืนค่าสำเนาส่วนเกินทั้งหมด:

fsetdiff(dt1, dt2, all = TRUE)

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

Set operations: `funion()`

ดึงแถวทั้งหมดที่พบในทั้งสอง data.table:

funion(dt1, dt2)

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

`funion()` และแถวที่ซ้ำกัน

แถวที่ซ้ำกันจะถูกละเว้นโดยค่าเริ่มต้น:

funion(dt1, dt2)

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

`funion()` และแถวที่ซ้ำกัน

all = TRUE: คืนค่าทุกแถว:

funion(dt1, dt2, all = TRUE) # rbind()

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

การลบแถวซ้ำเมื่อรวม `data.tables` หลายตาราง

สอง data.tables:

  1. ใช้ funion() เพื่อรวมแถวที่ไม่ซ้ำกัน

สามตารางขึ้นไป:

  1. รวมทุก data.tables ด้วย rbind() หรือ rbindlist()
  2. ระบุและลบแถวซ้ำด้วย duplicated() และ unique()
การ Join ข้อมูลด้วย data.table ใน R

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

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

Preparing Video For Download...