age_groups: Title Add age group column to data.frame

View source: R/add_age_groups.R

age_groupsR Documentation

Title Add age group column to data.frame

Description

Title Add age group column to data.frame

Usage

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
)

Arguments

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.

Value

Returns age groups

Examples

# 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)


DHatziioanou/simpleepi documentation built on Sept. 24, 2024, 5:25 a.m.