cube_vars_df_ | R Documentation |
Create a (partial) data cube and store it in a data frame
cube_vars_df_(
.data,
.list_vars,
sep = ".",
fun_list = list(n = ~nrow(.data)),
.all = FALSE,
.total = "Totale",
...
)
.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 ( |
.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 |
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.