# Example formats
age. <- discrete_format(
"Total" = 0:100,
"under 18" = 0:17,
"18 to under 25" = 18:24,
"25 to under 55" = 25:54,
"55 to under 65" = 55:64,
"65 and older" = 65:100)
sex. <- discrete_format(
"Total" = 1:2,
"Male" = 1,
"Female" = 2)
income. <- interval_format(
"Total" = 0:99999,
"below 500" = 0:499,
"500 to under 1000" = 500:999,
"1000 to under 2000" = 1000:1999,
"2000 and more" = 2000:99999)
# Example data frame
my_data <- dummy_data(1000)
# Call function
all_nested <- my_data |>
summarise_plus(class = c(year, sex, age),
values = income,
statistics = c("sum", "pct_group", "pct_total", "sum_wgt", "freq"),
formats = list(sex = sex., age = age.),
weight = weight,
nesting = "deepest",
na.rm = TRUE)
all_possible <- my_data |>
summarise_plus(class = c(year, sex, age, income),
values = c(probability),
statistics = c("sum", "p1", "p99", "min", "max", "freq", "freq_g0"),
formats = list(sex = sex.,
age = age.,
income = income.),
weight = weight,
nesting = "all",
na.rm = TRUE)
# Formats can also be passed as characters
single <- my_data |>
summarise_plus(class = c(year, age, sex),
values = weight,
statistics = c("sum", "mean"),
formats = list(sex = "sex.", age = "age."),
nesting = "single")
merge_back <- my_data |>
summarise_plus(class = c(year, age, sex),
values = weight,
statistics = c("sum", "mean"),
nesting = "deepest",
merge_back = TRUE)
certain_types <- my_data |>
summarise_plus(class = c(year, sex, age),
values = c(probability),
statistics = c("sum", "mean", "freq"),
formats = list(sex = sex.,
age = age.),
types = c("year", "year + age", "age + sex"),
weight = weight,
nesting = "all",
na.rm = TRUE)
Run the code above in your browser using DataLab