# In the below example, this function is used to calculate patient's age from
# their dates of birth
# import the data, replace missing values with NA and convert date into ISO
# format
data <- readRDS(system.file("extdata", "test_df.RDS", package = "cleanepi"))
data <- data %>%
replace_missing_values(target_columns = "dateOfBirth",
na_strings = "-99") %>%
standardize_dates(target_columns = "dateOfBirth",
error_tolerance = 0.0)
# calculate the age in 'years' and return the remainder in 'months'
age <- timespan(
data = data,
target_column = "dateOfBirth",
end_date = Sys.Date(),
span_unit = "years",
span_column_name = "age_in_years",
span_remainder_unit = "months"
)
Run the code above in your browser using DataLab