setops
Set operations for data tables
Similar to base's set functions, union
, intersect
, setdiff
and setequal
but for data.table
s. Additional all
argument controls if/how duplicate
rows are returned. bit64::integer64
is also supported.
Unlike SQL, data.table functions will retain order of rows in result.
- Keywords
- data
Usage
fintersect(x, y, all = FALSE)
fsetdiff(x, y, all = FALSE)
funion(x, y, all = FALSE)
fsetequal(x, y)
Arguments
- x,y
data.table
s.- all
Logical. Default is
FALSE
and removes duplicate rows on the result. WhenTRUE
, if there arexn
copies of a particular row inx
andyn
copies of the same row iny
, then:fintersect
will returnmin(xn, yn)
copies of that row.fsetdiff
will returnmax(0, xn-yn)
copies of that row.funion
will return xn+yn copies of that row.
Details
Columns of type complex
and list
are not supported except for funion
.
Value
A data.table in case of fintersect
, funion
and fsetdiff
. Logical TRUE
or FALSE
for fsetequal
.
References
See Also
data.table
, rbindlist
, all.equal.data.table
, unique
, duplicated
, uniqueN
, anyDuplicated
Examples
# NOT RUN {
x = data.table(c(1,2,2,2,3,4,4))
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, y) # setequal
# }