Skip to contents

Compute the age of the individuals at a certain date

Usage

addAge(
  x,
  cdm = lifecycle::deprecated(),
  indexDate = "cohort_start_date",
  ageName = "age",
  ageGroup = NULL,
  ageDefaultMonth = 1,
  ageDefaultDay = 1,
  ageImposeMonth = FALSE,
  ageImposeDay = FALSE,
  missingAgeGroupValue = "None"
)

Arguments

x

Table with individuals in the cdm.

cdm

A cdm_reference object.

indexDate

Variable in x that contains the date to compute the age.

ageName

Name of the new column that contains age.

ageGroup

List of age groups to be added.

ageDefaultMonth

Month of the year assigned to individuals with missing month of birth. By default: 1.

ageDefaultDay

day of the month assigned to individuals with missing day of birth. By default: 1.

ageImposeMonth

Whether the month of the date of birth will be considered as missing for all the individuals.

ageImposeDay

Whether the day of the date of birth will be considered as missing for all the individuals.

missingAgeGroupValue

Value to include if missing age.

Value

tibble with the age column added.

Examples

# \donttest{
cdm <- mockPatientProfiles()

cdm$cohort1 |>
  addAge()
#> # Source:   table<og_001_1714466008> [2 x 5]
#> # Database: DuckDB v0.10.1 [unknown@Linux 6.5.0-1018-azure:R 4.4.0/:memory:]
#>   cohort_definition_id subject_id cohort_start_date cohort_end_date   age
#>                  <dbl>      <dbl> <date>            <date>          <dbl>
#> 1                    1          1 2020-01-01        2020-04-01         27
#> 2                    1          1 2020-06-01        2020-08-01         27
CDMConnector::cdmDisconnect(cdm = cdm)
# }