Skip to contents

Compute the age of the individuals at a certain date

Usage

addAge(
  x,
  indexDate = "cohort_start_date",
  ageName = "age",
  ageGroup = NULL,
  ageMissingMonth = 1,
  ageMissingDay = 1,
  ageImposeMonth = FALSE,
  ageImposeDay = FALSE,
  missingAgeGroupValue = "None",
  name = NULL
)

Arguments

x

Table with individuals in the cdm.

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.

ageMissingMonth

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

ageMissingDay

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.

name

Name of the new table, if NULL a temporary table is returned.

Value

tibble with the age column added.

Examples

# \donttest{
cdm <- mockPatientProfiles()
#> Note: method with signature ‘DBIConnection#Id’ chosen for function ‘dbExistsTable’,
#>  target signature ‘duckdb_connection#Id’.
#>  "duckdb_connection#ANY" would also be valid

cdm$cohort1 |>
  addAge()
#> # Source:   table<og_001_1734613771> [?? x 5]
#> # Database: DuckDB v1.1.3 [unknown@Linux 6.8.0-1017-azure:R 4.4.2/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date   age
#>                   <int>      <int> <date>            <date>          <int>
#>  1                    1         10 1976-08-11        1983-08-14         33
#>  2                    2          4 1931-05-17        1931-07-22          7
#>  3                    3          6 2013-08-02        2013-08-19         36
#>  4                    1          7 1910-09-20        1913-06-22          8
#>  5                    3          9 1968-11-27        1977-01-19         13
#>  6                    1          2 1991-11-21        1997-10-31         22
#>  7                    1          3 1907-01-04        1912-07-22          2
#>  8                    1          5 1985-11-22        1992-12-18          6
#>  9                    1          1 1975-08-26        1983-02-11          2
#> 10                    2          8 1980-08-11        1985-10-05         18
mockDisconnect(cdm = cdm)
# }