Learn R Programming

generics (version 0.1.4)

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, ...)

Value

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

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

Arguments

x, y

Vectors to combine.

...

Other arguments passed on to methods.

el, set

Element and set to compare.

Methods

intersect()

generics:::methods_rd("intersect")

union()

generics:::methods_rd("union")

setdiff()

generics:::methods_rd("setdiff")

setequal()

generics:::methods_rd("setequal")

is.element()

generics:::methods_rd("is.element")

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.

Examples

Run this code
intersect(1:5, 4:8)
union(1:5, 4:8)

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

Run the code above in your browser using DataLab