do_by: split-apply-combine for vectors, with equal-length outptu

View source: R/genericrules.R

do_byR Documentation

split-apply-combine for vectors, with equal-length outptu

Description

Group x by one or more categorical variables, compute an aggregate, repeat that aggregate to match the size of the group, and combine results. The functions sum_by and so on are convenience wrappers that call do_by internally.

Usage

do_by(x, by, fun, ...)

sum_by(x, by, na.rm = FALSE)

mean_by(x, by, na.rm = FALSE)

min_by(x, by, na.rm = FALSE)

max_by(x, by, na.rm = FALSE)

Arguments

x

A bare variable name

by

a bare variable name, or a list of bare variable names, used to split x into groups.

fun

[function] A function that aggregates x to a single value.

...

passed as extra arguments to fun (e.g. na.rm=TRUE

na.rm

Toggle ignoring NA

See Also

Other cross-record-helpers: contains_exactly(), exists_any(), hb(), hierarchy(), is_complete(), is_linear_sequence(), is_unique()

Examples

x <- 1:10
y <- rep(letters[1:2], 5)
do_by(x, by=y, fun=max)
do_by(x, by=y, fun=sum)


validate documentation built on March 24, 2022, 5:07 p.m.