sets
Set Operations

### Description

Performs operations on vectors treated as sets.

### Usage

    union(x, y)
    intersect(x, y)
    setdiff(x, y)
    is.element(el, set)
    x %in% table
    setequal(x, y)

### Arguments

el, x | a vector of potential elements of the set.
set, table | a vector containing all elements of the set. It should not contain duplicate elements. Duplicates are silently removed.
x | a vector representing a set (like the set argument). It is replaced by as.vector(x).
y | a vector representing a set (like the set argument). It is replaced by as.vector(y).

Value

union | returns a vector of items in one or both of x and y.

intersect | returns a vector of items in both x and y.

setdiff | returns the elements in x that are not in y.

is.element | returns a logical vector the length of el indicating whether the items in el are elements of the specified set.

"x %in% table" | identical to is.element. A special operator.

setequal | returns TRUE if the two datasets are equal. That is, if all elements of x are in y and vice versa.

See Also
match, unique,
Examples

    x <- c(2, 3, 4)
    y <- c(3, 4, 5)
    union(x, y)
    intersect(x, y)
    setdiff(x, y)
    is.element(c("Belgium", "Rhode Island"), Sdatasets::state.name)
    c("Belgium", "Rhode Island") %in% Sdatasets::state.name
    setequal(union(x, y), union(y, x))

Package base version 6.1.5-18
Package Index