Skip to contents

This function calculates the age of subjects in a data frame based on their year of birth or birth date and the date of histology assessment. The method of calculation depends on the study specified in the data frame.

Usage

add_age(df)

Arguments

df

A data frame containing the columns `study`, `histology_assessment_date`, `birth_date_pat`, and `year_of_birth`. The `study` column is used to determine the method of age calculation. The `histology_assessment_date` must be in a date format that `lubridate::year()` can recognize.

Value

Returns the input data frame with an additional column `age` that contains the calculated age of the subjects.

Examples

df <- data.frame(
  study = c("embrace_i", "other_study"),
  histology_assesment_date = as.Date(c("2024-01-01", "2024-01-02")),
  birth_date_pat = c(1980, NA),
  year_of_birth = c(NA, 1990)
)
df_with_age <- add_age(df)
#> Warning: There was 1 warning in `dplyr::mutate()`.
#>  In argument: `age = lubridate::year(histology_assesment_date) -
#>   lubridate::year(birth_date_pat)`.
#> Caused by warning:
#> ! tz(): Don't know how to compute timezone for object of class numeric; returning "UTC".