\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}, \code{setdiff} and
\code{setequal} will discard any duplicated values in the arguments,
and they apply \code{\LinkA{as.vector}{as.vector}} to their arguments (and so
in particular coerce factors to character vectors).

\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.}}

\sQuote{\LinkA{plotmath}{plotmath}} for the use of \code{union} and
\code{intersect} in plot annotation.
\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}

