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

View source: R/split_apply_.R

split_apply_df_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_df_(
  .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.

...

additional optional arguments passed to res2df (estimator_name and value).

Value

a data frame with the function calls estimated for the groups defined by the combinations of variables.

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_df_(invented_wages, .vars = "gender", fun_list = fun)
split_apply_df_(invented_wages, .vars = c("gender", "sector"), fun_list = fun)


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