Skip to contents

Derive Age in Years

Usage

derive_var_age_years(dataset, age_var, age_unit = NULL, new_var)

Arguments

dataset

Input dataset.

age_var

AGE variable.

age_unit

AGE unit variable.

The AGE unit variable is used to convert AGE to 'years' so that grouping can occur. This is only used when the age_var variable does not have a corresponding unit in the dataset.

Default: NULL

Permitted Values: 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds'

new_var

New AGE variable to be created in years.

Value

The input dataset with new_var parameter added in years.

Details

This function is used to convert age variables into years. These can then be used to create age groups.

Author

Michael Thorpe

Examples


data <- data.frame(
  AGE = c(27, 24, 3, 4, 1),
  AGEU = c("days", "months", "years", "weeks", "years")
)

data %>%
  derive_var_age_years(., AGE, new_var = AAGE)

data.frame(AGE = c(12, 24, 36, 48)) %>%
  derive_var_age_years(., AGE, age_unit = "months", new_var = AAGE)