split_apply_: Apply a list of function calls to groups of a data frame

View source: R/split_apply_.R

split_apply_R Documentation

Apply a list of function calls to groups of a data frame

Description

Apply a list of function calls to groups of a data frame

Usage

split_apply_(.data, .vars, sep = ".", fun_list = list(n = ~nrow(.data)))

Arguments

.data

a data frame.

.vars

character vector with the names of the columns for which the data frame will be divided.

sep

a character string to separate the terms.

fun_list

a named list of formulas with the desired function calls to be evalutated on the data frame. The default value (list(n = ~nrow(.data))) returns the number of rows (observations) and stores it in a column named n.

Value

a nested list

Examples

data(invented_wages)
str(invented_wages)

# First create a list of function calls (with formulas)
fun <- list(m1 = ~weighted.mean(wage, sample_weights), s = ~sum(sample_weights))

# And then apply them to subsets of data defined by the combinations of variables
split_apply_(invented_wages, .vars = "gender", fun_list = fun)
split_apply_(invented_wages, .vars = c("gender", "sector"), fun_list = fun)
split_apply_(invented_wages, .vars = c("gender", "sector", "education"), fun_list = fun)

gibonet/cuber documentation built on Dec. 24, 2024, 5:17 p.m.