View source: R/add_age_groups.R
age_groups | R Documentation |
Title Add age group column to data.frame
age_groups(
age,
groups = c("0-4", "5-10", "11-16", "17-24", "25-30", "31-39", "40-59", "60-79", "80+"),
unknowns = c("-1", NA),
factor = FALSE
)
age |
age vector |
groups |
Input vector of age ranges in format "N1-N2" where N1 is the lower age and N2 the upper age. Mark range where max is infinite as "N1+" |
unknowns |
vector of Age values to be considered unknowns eg -1, NA, "not stated" |
factor |
Logical; should returned age groups be formatted as factor? Default is FALSE. |
Returns age groups
# df <- data.frame(ID = c(1:4), Age = c(8,-1,38,26))
# groups <- c('0-4', "5-10", "11-16", "17-24", "25-30", "31-39", "40-59", "60-79", "80+")
# df$group <- age_groups(df$Age, groups, unknowns, factor)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.