Set operations

R'de data.table ile Veri Birleştirme

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

Set operation functions

Given two data.tables with the same columns:

  • fintersect(): what rows do these two data.tables share in common?
  • funion(): what is the unique set of rows across these two data.tables?

  • fsetdiff(): what rows are unique to this data.table?

R'de data.table ile Veri Birleştirme

Set operations: `fintersect()`

Extract rows that are present in both data.tables

fintersect(dt1, dt2)

R'de data.table ile Veri Birleştirme

`fintersect()` and duplicate rows

Duplicate rows are ignored by default:

fintersect(dt1, dt2)

R'de data.table ile Veri Birleştirme

`fintersect()` and duplicate rows

all = TRUE: keep the number of copies present in both data.tables:

fintersect(dt1, dt2, all = TRUE)

R'de data.table ile Veri Birleştirme

Set operations: `fsetdiff()`

Extract rows found exclusively in the first data.table

fsetdiff(dt1, dt2)

R'de data.table ile Veri Birleştirme

`fsetdiff()` and duplicates

Duplicate rows are ignored by default:

fsetdiff(dt1, dt2)

R'de data.table ile Veri Birleştirme

`fsetdiff()` and duplicates

all = TRUE: return all extra copies:

fsetdiff(dt1, dt2, all = TRUE)

R'de data.table ile Veri Birleştirme

Set operations: `funion()`

Extract all rows found in either data.table:

funion(dt1, dt2)

R'de data.table ile Veri Birleştirme

`funion()` and duplicates

Duplicate rows are ignored by default:

funion(dt1, dt2)

R'de data.table ile Veri Birleştirme

`funion()` and duplicates

all = TRUE: return all rows:

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

R'de data.table ile Veri Birleştirme

Removing duplicates when combining many `data.tables`

Two data.tables:

  1. Use funion() to concatenate unique rows

Three or more:

  1. Concatenate all data.tables using rbind() or rbindlist()
  2. Identify and remove duplicates using duplicated() and unique()
R'de data.table ile Veri Birleştirme

Let's practice!

R'de data.table ile Veri Birleştirme

Preparing Video For Download...