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.
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".