A function that takes a vector of ages or age groups (either numeric or factor) and returns assigned age categories based on desired lower bin edges provided by the user.

aggregate_agecats(age, bin_edges_lower)

Arguments

age

Numeric or factor vector of ages

bin_edges_lower

list of numeric values for the lower edges of desired age group bins in panel 2. If ages are of type factor, all user-specified lower bin edges must match lower bin edges in the age data.

Examples

aggregate_agecats(seq(0, 90, by = 1), c(25, 45))
#>  [1] 0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24 
#> [13] 0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24  0-24 
#> [25] 0-24  25-44 25-44 25-44 25-44 25-44 25-44 25-44 25-44 25-44 25-44 25-44
#> [37] 25-44 25-44 25-44 25-44 25-44 25-44 25-44 25-44 25-44 45+   45+   45+  
#> [49] 45+   45+   45+   45+   45+   45+   45+   45+   45+   45+   45+   45+  
#> [61] 45+   45+   45+   45+   45+   45+   45+   45+   45+   45+   45+   45+  
#> [73] 45+   45+   45+   45+   45+   45+   45+   45+   45+   45+   45+   45+  
#> [85] 45+   45+   45+   45+   45+   45+   45+  
#> Levels: 0-24 25-44 45+