Skip to contents

This function takes a column of dates that can be in various common formats, and extracts the day, month, and year, returning them in a data frame.

Usage

extract_date(date_col, date_format = "dmy")

Arguments

date_col

A character vector representing the dates in various formats.

date_format

Optional. A character string specifying the date format ("dmy" or "mdy") to resolve ambiguities.

Value

A data frame with three columns: day, month, and year.

Examples

# mdy format
dates <- c("October 2, 2024", "10-02-2024", "10/02/2024")
result <- extract_date(dates, date_format = "mdy")
print(result)
#>   day month year
#> 1   2    10 2024
#> 2   2    10 2024
#> 3   2    10 2024
dates <- c("2 October 2024", "02-10-2024", "02/10/2024")
result <- extract_date(dates, date_format = "dmy")
print(result)
#>   day month year
#> 1   2    10 2024
#> 2   2    10 2024
#> 3   2    10 2024