\Header{split}{Divide into Groups}
\methalias{split.data.frame}{split}
\methalias{split.default}{split}
\keyword{category}{split}
\begin{Description}\relax
\code{split} divides the data in the vector \code{x} into the groups
defined by \code{f}.\end{Description}
\begin{Usage}
\begin{verbatim}
split(x, f)
split.default(x, f)
split.data.frame(x, f)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] vector containing the values to be divided into groups.
\item[\code{f}] a ``factor'' such that \code{factor(f)} defines the grouping,
or a list of such factors in which case their interaction is used
for the grouping.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{f} is recycled as necessary and if the length of \code{x} is not
a multiple of the length of \code{f} a warning is printed.\end{Details}
\begin{Value}
The value returned is a list of vectors containing the values for the
groups.  The components of the list are named by the factor levels
given be \code{f}.  If \code{f} is longer than \code{x} some of these
will be of zero length.\end{Value}
\begin{SeeAlso}\relax
\code{\Link{cut}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
n <- 10; nn <- 100
g <- factor(round(n * runif(n * nn)))
x <- rnorm(n * nn) + sqrt(as.numeric(g))
xg <- split(x, g)
boxplot(xg, col = "lavender", notch = TRUE, varwidth = TRUE)
sapply(xg, length)
sapply(xg, mean)

## Split a matrix into a list by columns
ma <- cbind(x = 1:10, y = (-4:5)^2)
split(ma, col(ma))

split(1:10, 1:2)
\end{ExampleCode}
\end{Examples}

