AgeGroups: Return A Factor Variable Of Age Groups - RDocumentation

SciencesPo (version 1.02.12)

Description

Return a factor variable using breaks and labels. The function will calculate the age based upon the to if given, otherwise the age.var will be used.

Usage

ageGroups(x = NULL, from, to, breaks, labels)

Arguments

xif a var containing the age already exists.fromThe date of origin, typically birthdate.toThe up to date to compute the age.breaksThe numeric break guide for grouping age.labelsThe labels for the age groups, can also be set to labels=NULL.

encoding

UTF-8

Examples

Run this code# The age groupings used by IBGE (grandes grupos).# simulate vector with 1000 age valuesage <- sample(0:100, 1000, replace = TRUE) mean(age); sd(age); ageGroups(age, breaks = c(0, 14, 64, Inf), labels = NULL ) ageGroups(age, breaks = c(0, 14, 64, Inf), labels = c("<14", "15-64", "65+") ) ibge_brks = c(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, Inf) ibge_lbls = c("0-4", "5-9", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54", "55-59", "60-64", "65-69", "70+") ageGroups(age, breaks = ibge_brks, labels = ibge_lbls )

Run the code above in your browser using DataLab

Tag » How To Group Ages In Rstudio