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,
ageUnit = "years",
missingAgeGroupValue = "None",
name = NULL,
type = "numeric"
)Arguments
- x
A table containing individuals in a CDM reference.
- indexDate
Name of a date column in
x, or a single date to use for all rows, used as the reference date.- ageName
Name of the age column to add.
- ageGroup
If not
NULL, a list of age-group vectors.- ageMissingMonth
Month of the year assigned when month of birth is missing.
- ageMissingDay
Day of the month assigned when day of birth is missing.
- ageImposeMonth
If
TRUE, month of birth is treated as missing for all individuals.- ageImposeDay
If
TRUE, day of birth is treated as missing for all individuals.- ageUnit
Unit in which to express age:
"years","months", or"days".- missingAgeGroupValue
Value to use when age is missing.
- name
Name of the new table. If
NULL, a temporary table is returned.- type
Type of the created column(s). Counts, days, age, and observation durations can be
"numeric"or"integer". Flag columns can also be"logical". Field columns can use"auto"to preserve the source type, or can be converted to"numeric","integer","logical", or"character".
Examples
# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles(source = "duckdb")
#> Warning: There are observation period end dates after the current date: 2026-07-24
#> ℹ The latest max observation period end date found is 2029-11-26
#> duckdb is keeping downloaded extensions in a temporary directory:
#> ℹ /tmp/Rtmp0gh70B/duckdb/extensions
#> This is removed when the R session ends, so extensions are re-downloaded each session.
#> ℹ To keep them, point `options(duckdb.extension_directory =)` or the `DUCKDB_EXTENSION_DIRECTORY` environment variable at a permanent path.
cdm$cohort1 |>
addAge()
#> # A query: ?? x 5
#> # Database: DuckDB 1.5.4 [unknown@Linux 6.17.0-1020-azure:R 4.6.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date age
#> <int> <int> <date> <date> <dbl>
#> 1 2 6 1993-04-16 1996-10-08 31
#> 2 1 3 1980-08-13 1987-10-18 18
#> 3 2 1 1983-08-01 1995-08-02 6
#> 4 3 10 1963-11-15 1990-06-10 2
#> 5 1 7 1966-01-28 1966-03-16 23
#> 6 3 9 1977-05-20 1980-10-28 33
#> 7 2 2 1905-01-15 1906-02-20 3
#> 8 3 5 1956-11-16 1966-08-17 13
#> 9 1 8 1942-03-26 1954-05-24 37
#> 10 2 4 1990-06-19 1990-11-17 35
# }
