add_ages: Add age and census age groups to a data frame

View source: R/add_ages.R

add_agesR Documentation

Add age and census age groups to a data frame

Description

Takes a data frame with a year born variable or age variable and creates four new variables:

Usage

add_ages(
  dataset,
  year_born_var,
  age_var,
  year_of_survey = 0,
  survey_date_var = "NULL"
)

Arguments

dataset

The name of the data frame for the function to modify, usually piped into your main data frame

year_born_var

NO DFAULT; You may either provide a year_born_var or an age_var, not both

age_var

NO DFAULT

year_of_survey

DEFAULT = Whatever the current year is. Used to calculate respondent ages. If you are using old survey data from a previous year, you can input the year here as a numeric value (e.g. 1994)

survey_date_var

DEFAULT = 'NULL'. A date variable in the dataset that specifies when the survey was taken. If specified, ages will be calculated off this and not the year_of_survey argument. Especially helpful for trended data that spans multiple years

Details

1. year_born_numeric 2. age_numeric 3. census_age_groups 4. census_age_groups_6 (same as census_age_groups, but with split 18-34 into 18-24 & 25-34)

Examples

responses <- tibble::tibble(
  year_born = c(
  2000,
  2001
  ),
  age = c(
  20,
  19
  )
)

add_ages(responses, year_born_var = year_born)
add_ages(responses, age_var = age)

nick-moffitt/orderlabel documentation built on Nov. 9, 2023, 6:39 p.m.