\Header{sets}{Set Operations}
\alias{intersect}{sets}
\alias{is.element}{sets}
\alias{setdiff}{sets}
\alias{setequal}{sets}
\alias{union}{sets}
\keyword{misc}{sets}
\begin{Description}\relax
Performs \bold{set} union, intersection, (asymmetric!) difference,
equality and membership on two vectors.\end{Description}
\begin{Usage}
\begin{verbatim}
union(x, y)
intersect(x, y)
setdiff(x, y)
setequal(x, y)
is.element(el, set)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, y, el, set}] vectors (of the same mode) containing a sequence
of items (conceptually) with no duplicated values.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Each of \code{union}, \code{intersect} and \code{setdiff} will remove
any duplicated values in the arguments.

\code{is.element(x, y)} is identical to \code{x \%in\% y}.\end{Details}
\begin{Value}
A vector of the same \code{\Link{mode}} as \code{x} or \code{y} for
\code{setdiff} and \code{intersect}, respectively, and
of a common mode for \code{union}.

A logical scalar for \code{setequal} and a logical of the same
length as \code{x} for \code{is.element}.\end{Value}
\begin{Author}\relax
B. D. Ripley\end{Author}
\begin{SeeAlso}\relax
\code{\Link{\%in\%}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
(x <- c(sort(sample(1:20, 9)),NA))
(y <- c(sort(sample(3:23, 7)),NA))
union(x, y)
intersect(x, y)
setdiff(x, y)
setdiff(y, x)
setequal(x, y)

## True for all possible x & y :
setequal( union(x,y),
          c(setdiff(x,y), intersect(x,y), setdiff(y,x)))

is.element(x, y)# length 10
is.element(y, x)# length  8
\end{ExampleCode}
\end{Examples}

