Learn R Programming

doBy (version 4.6.21)

by-split: Split a data frame

Description

Split a dataframe according to the levels of variables in the dataframe. The variables to split by can be given as a formula or as a character vector.

Usage

split_by(data, formula, drop = TRUE)

splitBy(formula, data = parent.frame(), drop = TRUE)

# S3 method for splitByData head(x, n = 6L, ...)

# S3 method for splitByData tail(x, n = 6L, ...)

Value

A list of dataframes.

Arguments

data

A data frame

formula

Variables to split data frame by, as as.quoted variables, a formula or character vector.

drop

Logical indicating if levels that do not occur should be dropped. Deprecated; levels that do not occur are ignored.

x

An object.

n

A single integer. If positive or zero, size for the resulting object: number of elements for a vector (including lists), rows for a matrix or data frame or lines for a function. If negative, all but the "n" last/first number of elements of "x".

...

Arguments to be passed to or from other methods.

Author

Søren Højsgaard, sorenh@math.aau.dk

See Also

orderBy, order_by, summaryBy, summary_by, transformBy, transform_by

Examples

Run this code

data(dietox, package="doBy")
splitBy(formula = ~Evit + Cu, data = dietox)
splitBy(formula = c("Evit", "Cu"), data = dietox)

splitBy(~Treatment + Type, data=CO2)
splitBy(c("Treatment", "Type"), data=CO2)

x <- splitBy(~Treatment, data=CO2)
head(x)
tail(x)

Run the code above in your browser using DataLab