R/cal_min_max_date.R
cal_min_max_date.Rd
This function derives the earliest/latest date as ISO8601 datetime
cal_min_max_date(
raw_dataset,
date_variable,
time_variable,
val_type = "min",
date_format,
time_format
)
Raw source data frame
Single character string. Name of the date variable
Single character string. Name of the time variable
Single character string determining whether to look for the earliest or the latest datetime combination. Permitted values: "min", "max". Default to "min".
Format of source date variable
Format of source time variable
Data frame with 2 columns: unique patient_number and datetime variable column storing the earliest/latest datetime.
ex_raw <- tibble::tribble(
~patient_number, ~EX_ST_DT, ~EX_ST_TM,
"001", "25-04-2022", "10:20",
"001", "25-04-2022", "10:15",
"001", "25-04-2022", "10:19",
"002", "26-05-2022", "UNK:UNK",
"002", "26-05-2022", "05:59"
)
min <- cal_min_max_date(ex_raw,
date_variable = "EX_ST_DT",
time_variable = "EX_ST_TM",
val_type = "min",
date_format = "dd-mmm-yyyy",
time_format = "H:M"
)
max <- cal_min_max_date(ex_raw,
date_variable = "EX_ST_DT",
time_variable = "EX_ST_TM",
val_type = "max",
date_format = "dd-mmm-yyyy",
time_format = "H:M"
)