cube_vars_df_: Create a (partial) data cube and store it in a data frame

View source: R/split_apply_.R

cube_vars_df_R Documentation

Create a (partial) data cube and store it in a data frame

Description

Create a (partial) data cube and store it in a data frame

Usage

cube_vars_df_(
  .data,
  .list_vars,
  sep = ".",
  fun_list = list(n = ~nrow(.data)),
  .all = FALSE,
  .total = "Totale",
  ...
)

Arguments

.data

a data frame.

.list_vars

a list of character vectors with the combinations of variables for which functions will be evaluated.

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.

.all

logical, indicating if functions' evaluations on the complete dataset have to be done.

.total

character string with the value to give to the "total" combinations (default: "Totale").

...

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

Examples

data(invented_wages)
str(invented_wages)

# Create a list of character vectors with the combinations of variables
# for which we want to evalutate function calls
list_all_vars <- unlist(combn_char(c("gender", "sector")), recursive = FALSE)
list_all_vars           # All the combinations of the two variables        
list_all_vars[c(1, 3)]  # Keep only the first and the third

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

# And finally create the data cube, but only on the given combinations of
# variables
cube_vars_df_(invented_wages, .list_vars = list_all_vars[c(2, 3)], fun_list = fun)

# Setting .all = TRUE adds the evalutations on the complete dataset
cube_vars_df_(invented_wages, .list_vars = list_all_vars[c(2, 3)], fun_list = fun, .all = TRUE)


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