[ top | up ]

Divide into Groups

Usage

split(x, f)

Arguments

x vector containing the values to be divided into groups.
f a factor which defines the grouping.

Description

split divides the data in the vector x into the groups defined by the factor f.

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 of f.

Examples

n <- 10; nn <- 100
g <- factor(round(n * runif(n * nn)))
x <- rnorm(n * nn) + sqrt(codes(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))