Takes the age group stored in age_group and creates two variables, age_min and age_max with the age boundaries of the group. By default, separate_age_groups() assumes that the age group definitions are separated by a dash ("-"), possibly with whitespace on either side. The separator can be specified using the sep argument.

separate_age_groups(data, age_group = age_group, ...,
  sep = "\\s*-\\s*", into = c("age_min", "age_max"))

Arguments

data

A data frame.

age_group

Unquoted column name containing the age grouping.

...

Not used other than to require explicit naming of arguments.

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.

into

Character vector of column names for separated age_group. If NULL, then _min and _max will be appended to the name of the age_group column. Must be two names in the order min then max.

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, standardize_age_groups

Examples

d_age_group <- dplyr::tibble( id = 1:4, age_group = c("0 - 4", "10 - 14", "65 - 69", "85+") ) separate_age_groups(d_age_group)
#> # A tibble: 4 x 4 #> id age_group age_min age_max #> <int> <chr> <dbl> <dbl> #> 1 1 0 - 4 0 4 #> 2 2 10 - 14 10 14 #> 3 3 65 - 69 65 69 #> 4 4 85+ 85 Inf