Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

setops

Set operations


Description

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

Usage

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()

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.

Examples

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

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

generics

Common S3 Generics not Provided by Base R Methods Related to Model Fitting

v0.1.0
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], Max Kuhn [aut], Davis Vaughan [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.