\HeaderA{sets}{Set Operations}{sets}
\aliasA{intersect}{sets}{intersect}
\aliasA{is.element}{sets}{is.element}
\aliasA{setdiff}{sets}{setdiff}
\aliasA{setequal}{sets}{setequal}
\aliasA{union}{sets}{union}
\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{\LinkA{mode}{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{SeeAlso}\relax
\code{\LinkA{\%in\%}{.Rpcent.in.Rpcent.}}
\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}

