Collapse variable into subgroup positions
make_grps(x, grps)
Character vector
Named list of variable values or positions within vector x
Named list of variable values from given positions
ages <- c("Under 5 years", "5 to 9 years", "10 to 14 years", "15 to 17 years",
"18 and 19 years", "20 years", "21 years", "22 to 24 years",
"25 to 29 years", "30 to 34 years", "35 to 39 years", "40 to 44 years")
age_grps <- list(
under18 = 1:4,
ages18_24 = 5:8,
ages18_34 = 5:10
)
make_grps(ages, age_grps)
#> $under18
#> [1] "Under 5 years" "5 to 9 years" "10 to 14 years" "15 to 17 years"
#>
#> $ages18_24
#> [1] "18 and 19 years" "20 years" "21 years" "22 to 24 years"
#>
#> $ages18_34
#> [1] "18 and 19 years" "20 years" "21 years" "22 to 24 years"
#> [5] "25 to 29 years" "30 to 34 years"
#>