[ top | up ]

Divide into Groups

Syntax

split(x, groups)

Arguments

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

Description

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

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 group.

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))