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

unionreturns a vector of items in one or both of x and y.
intersectreturns a vector of items in both x and y.
setdiffreturns the elements in x that are not in y.
is.elementreturns 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.
setequalreturns 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.1-7
Package Index