Skip to contents

This function does some tedious regex replacement to make common labels we use for age groups (i.e. syntactically correct variable names) to labels meant for display in charts and tables. The main features are replacing underscores between numbers with dashes, adding space between text and numbers, replacing symbols, and parsing numbers. So "ages00_17" becomes "Ages 0-17", and "ages65plus" becomes "Ages 65+". Of course, you could also use this for other numeric ranges, like years.

Usage

age_lbls(x)

Arguments

x

A string vector of labels to clean up

Value

A string vector of display-worthy labels

Examples

a <- c("ages00_17", "ages18_64", "ages65plus", "under18", "ages18up")
age_lbls(a)
#> [1] "Ages 0-17"  "Ages 18-64" "Ages 65+"   "Under 18"   "Ages 18+"