format_age_year: Create consistent, complete single-year age groups

Description Usage Arguments Details Value See Also Examples

View source: R/format_age.R

Description

Given a vector of age group labels, create a factor that contains levels for all ages between break_min and break_max. The labels may include an "open" age group with no upper limit. Apart from the open age group, all the age groups have a width of one year.

Usage

1
format_age_year(x, break_min = 0, break_max = 100, open_last = TRUE)

Arguments

x

A vector of age group labels.

break_min

An integer or NULL. Defaults to 0.

break_max

An integer or NULL. Defaults to 100.

open_last

Whether the final age group has no upper limit. Defaults to TRUE.

Details

Even when an age group between break_min and break_max is not included in x, format_age_year still creates a level for it.

x must consist of labels for single-year age groups, such as "22", or open age groups, such as "100+". x must not contain labels for multi-year age groups such as "20-24".

If break_min or break_max is set to NULL, rather than to a specific value, then format_age_year finds the narrowest range that accommodates the data.

All age groups in x must be single-year age groups, except for any open age groups.

If x contains NA, then the levels of the factor created by format_age_year also contain NA.

Value

A factor with the same length as x.

See Also

Other functions for reformating age group labels are

date_to_age_year creates one-year age groups from dates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
format_age_year(x = c("10", "3", "100+", "77"))

## allow 'break_min' and 'break_max' to be
## determined by the data
format_age_year(x = c(22, 7, 30),
                break_min = NULL,
                break_max = NULL)

## allow 'break_max' to be determined
## by the data, which includes an
## open age group
format_age_year(x = c("17", "10+"),
                break_max = NULL)

## oldest age group is closed
format_age_year(x = c(10, 3, 77),
                open_last = FALSE)

johnrbryant/demprep documentation built on Dec. 31, 2021, 11:58 a.m.