Union (union()
), intersect (intersect()
), difference (setdiff()
),
and equality (setequal()
) for two vectors representing sets. Determine
membership with is.element()
.
intersect(x, y, ...) union(x, y, ...) setdiff(x, y, ...) setequal(x, y, ...) is.element(el, set, ...)
x, y | Vectors to combine. |
---|---|
... | Other arguments passed on to methods. |
el, set | Element and set to compare. |
For union()
, intersect()
, and setdiff()
, a vector with all
duplicate removed.
For setequal()
and is.element()
, a logical TRUE
or FALSE
.`
These functions override the set functions provided in base to make them generic so that packages can provide methods for different data types. The default methods call the base versions.
intersect()
No methods found in currently loaded packages.
union()
No methods found in currently loaded packages.
setdiff()
No methods found in currently loaded packages.
setequal()
No methods found in currently loaded packages.
is.element()
No methods found in currently loaded packages.
intersect(1:5, 4:8)#> [1] 4 5union(1:5, 4:8)#> [1] 1 2 3 4 5 6 7 8setdiff(1:5, 4:8)#> [1] 1 2 3setdiff(4:8, 1:5)#> [1] 6 7 8