derive_var_age_years: Derive Age in Years

Description Usage Arguments Details Value Author(s) Examples

View source: R/derive_vars_aage.R

Description

Derive Age in Years

Usage

1
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.

Details

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

Value

The input dataset with new_var paramater added in years.

Author(s)

Michael Thorpe

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(dplyr, warn.conflicts = FALSE)

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)

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.