Rev 13423 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{split}\title{Divide into Groups}\alias{split}\alias{split.default}\alias{split.data.frame}\description{\code{split} divides the data in the vector \code{x} into the groupsdefined by \code{f}.}\usage{split(x, f)split.default(x, f)split.data.frame(x, f)}\arguments{\item{x}{vector containing the values to be divided into groups.}\item{f}{a ``factor'' such that \code{factor(f)} defines the grouping,or a list of such factors in which case their interaction is usedfor the grouping.}}\details{\code{f} is recycled as necessary and if the length of \code{x} is nota multiple of the length of \code{f} a warning is printed.}\value{The value returned is a list of vectors containing the values for thegroups. The components of the list are named by the factor levelsgiven be \code{f}. If \code{f} is longer than \code{x} some of thesewill be of zero length.}\seealso{\code{\link{cut}}}\examples{n <- 10; nn <- 100g <- 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 columnsma <- cbind(x = 1:10, y = (-4:5)^2)split(ma, col(ma))split(1:10, 1:2)}\keyword{category}