by-split: Split a data frame into groups defined by variable(s)

by-splitR Documentation

Split a data frame into groups defined by variable(s)

Description

Split a dataframe according to the levels of variables in the dataframe. Uses vparse() to interpret flexible input.

Usage

split_by(data., ..., omit = TRUE)

splitBy(formula, data, omit = TRUE)

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

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

split_by.legacy(data, formula, drop = TRUE)

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

Arguments

data.

A data frame (or tibble) to split

...

Variables defining the groups

omit

If TRUE (default), group-defining variables are omitted in each split group

formula

A right hand sided formula (for the old interface)

data

A data frame (for the old interface)

x

A splitByData object.

n

An integer vector.

drop

Obsolete

Value

An object of class \"splitByData\" (a named list with group attributes)

Author(s)

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

See Also

orderBy, order_by, summaryBy, summary_by, transformBy, transform_by

Examples


split_by(CO2, ~Treatment+Type)
split_by(CO2, Treatment, Type)
split_by(CO2, c("Treatment", "Type"))
split_by(CO2, "Treatment", "Type")

x <- split_by(CO2, "Treatment", "Type")
head(x, 3)
tail(x, 3)

## Via wrapper:
foo2 <- function(x) {
 x <- rlang::enquo(x)
 split_by(CO2, !!x)
}
foo2(~Treatment)

## The "Old" interface
splitBy(~Treatment + Type, CO2)
splitBy(~Treatment + Type, data=CO2)
splitBy(c("Treatment", "Type"), data=CO2)


doBy documentation built on June 30, 2025, 1:06 a.m.