setops: Set operations

Description Usage Arguments Details Value Methods Examples

Description

Union (union()), intersect (intersect()), difference (setdiff()), and equality (setequal()) for two vectors representing sets. Determine membership with is.element().

Usage

1
2
3
4
5
6
7
8
9
intersect(x, y, ...)

union(x, y, ...)

setdiff(x, y, ...)

setequal(x, y, ...)

is.element(el, set, ...)

Arguments

x, y

Vectors to combine.

...

Other arguments passed on to methods.

el, set

Element and set to compare.

Details

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.

Value

For union(), intersect(), and setdiff(), a vector with all duplicate removed.

For setequal() and is.element(), a logical TRUE or FALSE.'

Methods

intersect()

\Sexpr[stage=render,results=rd]{generics:::methods_rd("intersect")}

union()

\Sexpr[stage=render,results=rd]{generics:::methods_rd("union")}

setdiff()

\Sexpr[stage=render,results=rd]{generics:::methods_rd("setdiff")}

setequal()

\Sexpr[stage=render,results=rd]{generics:::methods_rd("setequal")}

is.element()

\Sexpr[stage=render,results=rd]{generics:::methods_rd("is.element")}

Examples

1
2
3
4
5
intersect(1:5, 4:8)
union(1:5, 4:8)

setdiff(1:5, 4:8)
setdiff(4:8, 1:5)

Example output

Attaching package: 'generics'

The following objects are masked from 'package:base':

    as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
    setequal, union

[1] 4 5
[1] 1 2 3 4 5 6 7 8
[1] 1 2 3
[1] 6 7 8

generics documentation built on Oct. 31, 2020, 9:07 a.m.