x <- c("03 Jan 2018", "07/03/1982", "08/20/85")
# The below will coerce values where the month is written in letters only
# into Date.
as.Date(lubridate::parse_date_time(x, orders = c("Ybd", "dby")))
# coerce values where the month is written in letters or numbers into Date.
as.Date(lubridate::parse_date_time(x, orders = c("dmy", "Ymd")))
# How to use standardize_dates()
data <- readRDS(system.file("extdata", "test_df.RDS", package = "cleanepi"))
# convert values in the 'date.of.admission' column into "%Y-%m-%d"
# format
dat <- standardize_dates(
data = data,
target_columns = "date.of.admission",
format = NULL,
timeframe = as.Date(c("2021-01-01", "2021-12-01")),
error_tolerance = 0.4,
orders = list(
world_named_months = c("Ybd", "dby"),
world_digit_months = c("dmy", "Ymd"),
US_format = c("Omdy", "YOmd")
)
)
# print the report
print_report(dat, "date_standardization")
Run the code above in your browser using DataLab