Standardizes age groups to match seer_std_ages. Adds an age_group column, or overwites the existing age_group column if present. The age_var column can be either an actual age or an age group. If the column is numeric, it assumed to be an actual age, otherwise if it contains any non-numeric characters it is assumed to be an age group that will be expanded using separate_age_groups(). If multiple standardized age groups match a given age, the function will throw an error.

standardize_age_groups(data = NULL, age_group = age_group,
  std_age_groups = fcds_const("age_group"), ...)

Arguments

data

A data frame.

age_group

The column containing age or age group. This column will be overwritten if named age_group. If the column is numeric or can be coerced to numeric, it is treated as actual age. Otherwise it is assumed to contain age groups.

std_age_groups

Standard age groups, in the desired order.

...

Arguments passed on to separate_age_groups

sep

Separator between columns.If character, is interpreted as a regular expression. The default value is a regular expression that matches any sequence of non-alphanumeric values.If numeric, interpreted as positions to split at. Positive values start at 1 at the far-left of the string; negative value start at -1 at the far-right of the string. The length of sep should be one less than into.

See also

format_age_groups() for the specification of the age group label format and to convert age boundaries into age group labels.

Other age processors: complete_age_groups, filter_age_groups, format_age_groups, recode_age_groups, separate_age_groups

Examples

dplyr::tibble( id = 1:4, age_group = c("0 - 4", "10-14", "65-69", "85+") ) %>% standardize_age_groups()
#> # A tibble: 4 x 2 #> id age_group #> <int> <ord> #> 1 1 0 - 4 #> 2 2 10 - 14 #> 3 3 65 - 69 #> 4 4 85+