This function helps to recode age groups into new groups that are equal to or overlap the original age grouping.
recode_age_groups(data, breaks, age_group = age_group)
data | A data frame, containin age group labels in the |
---|---|
breaks | The breaks at which the lower bounds of age groups should be
defined. If the first and last elements are |
age_group | Unquoted column name containing the age grouping. |
Other age processors: complete_age_groups
,
filter_age_groups
,
format_age_groups
,
separate_age_groups
,
standardize_age_groups
d_age_groups <- dplyr::tibble( age_min = seq(0, 25, 5), age_max = seq(4, 29, 5) ) %>% format_age_groups() d_age_groups#> # A tibble: 6 x 3 #> age_min age_max age_group #> <dbl> <dbl> <chr> #> 1 0 4 0 - 4 #> 2 5 9 5 - 9 #> 3 10 14 10 - 14 #> 4 15 19 15 - 19 #> 5 20 24 20 - 24 #> 6 25 29 25 - 29#> # A tibble: 6 x 3 #> age_min age_max age_group #> <dbl> <dbl> <ord> #> 1 0 9 0 - 9 #> 2 0 9 0 - 9 #> 3 10 19 10 - 19 #> 4 10 19 10 - 19 #> 5 20 24 20 - 24 #> 6 25 Inf 25+# Use maximum age in data for upper bound of highest group recode_age_groups(d_age_groups, breaks = c(10, 20, 25, NA))#> # A tibble: 6 x 3 #> age_min age_max age_group #> <dbl> <dbl> <ord> #> 1 0 9 0 - 9 #> 2 0 9 0 - 9 #> 3 10 19 10 - 19 #> 4 10 19 10 - 19 #> 5 20 24 20 - 24 #> 6 25 29 25 - 29# Use minimum age in data for lower bound of lowest group d_age_groups %>% dplyr::filter(age_min >= 5) %>% recode_age_groups(breaks = c(NA, 10, 20, 25))#> # A tibble: 5 x 3 #> age_min age_max age_group #> <dbl> <dbl> <ord> #> 1 5 9 5 - 9 #> 2 10 19 10 - 19 #> 3 10 19 10 - 19 #> 4 20 24 20 - 24 #> 5 25 Inf 25+# Dichotomize recode_age_groups(d_age_groups, breaks = 20)#> # A tibble: 6 x 3 #> age_min age_max age_group #> <dbl> <dbl> <ord> #> 1 0 19 0 - 19 #> 2 0 19 0 - 19 #> 3 0 19 0 - 19 #> 4 0 19 0 - 19 #> 5 20 Inf 20+ #> 6 20 Inf 20+#> # A tibble: 5 x 3 #> age_min age_max age_group #> <dbl> <dbl> <ord> #> 1 5 19 5 - 19 #> 2 5 19 5 - 19 #> 3 5 19 5 - 19 #> 4 20 29 20 - 29 #> 5 20 29 20 - 29