Compute Weighted Mean Across a List of Data Frames (with optional grouping)
run_weighted_mean.Rd
Compute Weighted Mean Across a List of Data Frames (with optional grouping)
Arguments
- data_list
A named list of data frames, (e.g., across countries or years).
- var_name
A string specifying the variable name (e.g., "dhi", "pilabour") to compute the mean on.
- wgt_name
An optional string specifying the weight variable to be used. If
NULL
, equal weights are assumed.- na.rm
Logical. If
TRUE
, missing values invar_name
orwgt_name
are removed.- by
Optional string giving the name of a categorical variable to split the data within each data frame before computing the mean.
Examples
if (FALSE) { # \dontrun{
data <- lissyrtools::lissyuse(data = c("de", "es", "uk"), vars = c("dhi", "age", "pi11", "region_c", "area_c", "educ", "emp"), from = 2016)
data %>%
purrr::map(~ .x %>% filter(relation == 1000)) %>%
run_weighted_mean("dhi", "hpopwgt")
data %>%
purrr::map(~ .x %>% filter(age > 25 & age <65)) %>%
run_weighted_mean("pi11", "ppopwgt", by = "educ")
} # }