Skip to contents

Extract numeric upper bounds from age class labels for binning or recoding age variables. Use when creating new age classes from labeled data for tabulation or reporting.

Usage

get_age_upper_bounds(labels)

Arguments

labels

character vector. Age class labels (e.g., from value_labels).

Value

numeric vector. Upper bounds for each age class.

Details

  • Detects labels indicating minimum age (e.g., 'less than', 'under').

  • Extracts trailing numeric value from each label.

  • Adjusts minimum class to be exclusive (subtracts 1).

  • Returns a numeric vector; does not modify by reference.

  • Assumes labels are character and contain numeric bounds; errors if not.

Settings

None.

See also

Examples

labels <- c('Under 5', '5-9', '10-14', '15+')
get_age_upper_bounds(labels)
#> [1]  4  9 14 NA