Get person's age
get_person_age.RdA helper function primarily used by table_one() to derive the age of the
person at enrollment but may have additional uses to derive age at an index
event or date (in years). See details and examples.
Arguments
- ds
A PicnicHealth data set list object.
- index_type
The type of index against which to calculate age. Must be in
c('event', 'date'), and defaults to'event'.- index_event
What event to use to calculate age. Only used if
index_type = 'event'. Currently only'enrollment'is available, the default.- index_date
A vector of dates used to calculate age. Only used if index_type = "date". Defaults to
NULL.
Value
A data frame, one row per person, with a column for person_id and age,
i.e. person's age in years.
Details
If called with no other arguments than the PicnicHealth data set, i.e. ds,
then the default return value is age at enrollment.
If specifying index_date, the number of elements (rows) in the vector of
index_date must be equal to the number of rows in the person table because
age is calculated using the date_of_birth column in that table. If death_date
precedes enrollment date or specific index_date, age at death_date will be
calculated instead.
Beyond its use in table_one(), this function may be useful to add an
additional column to an existing analytic data.frame that already contains
person_id using dplyr::left_join() to include age. See examples.
See also
get_concept_names(), get_observation_periods(), get_person_age(),
get_person_clinical_document_span(), get_person_enrollment_date(),
get_person_ethnicity(), get_person_hospitalization_info(),
get_person_num_care_sites(), get_person_num_providers(),
get_person_race(), get_person_sex(), get_person_state_province(),
get_person_visit_span(), table_one()
Examples
if (FALSE) { # \dontrun{
# Get age at enrollment:
get_person_age(ds = ds)
# Get age at death:
get_person_age(ds = ds, index_type = 'date', index_date = as.Date(ds$person$death_date))
# Add `age` to an analytic data set that contains `person_id`:
analytic_dataset %>%
left_join(get_person_age(ds))
} # }