Generates a single-year age variable from an age-group variable.
For closed age groups, ages are sampled uniformly from the specified
age range. For open-ended age groups (for example, "85 years and over"),
ages are sampled uniformly between the lower age bound and
max_age.
Examples
population_dt <- data.table::data.table(
AgeGroup = c(
rep("25-34 years", 5),
rep("85 years and over", 5)
)
)
add_age_years(
population_dt,
age_group = "AgeGroup"
)
#> AgeGroup age
#> <char> <int>
#> 1: 25-34 years 31
#> 2: 25-34 years 29
#> 3: 25-34 years 30
#> 4: 25-34 years 28
#> 5: 25-34 years 30
#> 6: 85 years and over 93
#> 7: 85 years and over 89
#> 8: 85 years and over 89
#> 9: 85 years and over 99
#> 10: 85 years and over 92
