powered by
Converts a vector of dates in various formats to a standard date format. The function tries to parse each date using predefined formats and returns the first valid date found for each entry. If a date cannot be interpreted, it is assigned as NA.
NA
convert_to_date(date_vector, output_type = c("date", "datetime"))
A vector of Date or POSIXct objects, or NA if the date cannot be converted.
Date
POSIXct
A character vector containing dates in various formats.
Type of object to return: "date" for Date, "datetime" for POSIXct.
dates <- c("2025-04-10", "10/04/2025", "April 10, 2025") converted_dates <- convert_to_date(dates) print(converted_dates)
Run the code above in your browser using DataLab