| setops {data.table} | R Documentation |
Set operations for data tables
Description
Similar to base R set functions, union, intersect, setdiff and setequal but for data.tables. Additional all argument controls how duplicated rows are handled. Functions fintersect, setdiff (MINUS or EXCEPT in SQL) and funion are meant to provide functionality of corresponding SQL operators. Unlike SQL, data.table functions will retain row order.
Usage
fintersect(x, y, all = FALSE)
fsetdiff(x, y, all = FALSE)
funion(x, y, all = FALSE)
fsetequal(x, y, all = TRUE)
Arguments
x, y |
|
all |
Logical. Default is
|
Details
bit64::integer64 columns are supported but not complex and list, except for funion.
Value
A data.table in case of fintersect, funion and fsetdiff. Logical TRUE or FALSE for fsetequal.
References
https://db.apache.org/derby/papers/Intersect-design.html
See Also
data.table, rbindlist, all.equal.data.table, unique, duplicated, uniqueN, anyDuplicated
Examples
x = data.table(c(1,2,2,2,3,4,4))
x2 = data.table(c(1,2,3,4)) # same set of rows as x
y = data.table(c(2,3,4,4,4,5))
fintersect(x, y) # intersect
fintersect(x, y, all=TRUE) # intersect all
fsetdiff(x, y) # except
fsetdiff(x, y, all=TRUE) # except all
funion(x, y) # union
funion(x, y, all=TRUE) # union all
fsetequal(x, x2, all=FALSE) # setequal
fsetequal(x, x2) # setequal all