convert_to_date {Tivy} | R Documentation |
Convert dates to standard format
Description
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
.
Usage
convert_to_date(date_vector, output_type = c("date", "datetime"))
Arguments
date_vector |
A character vector containing dates in various formats. |
output_type |
Type of object to return: "date" for Date, "datetime" for POSIXct. |
Value
A vector of Date
or POSIXct
objects, or NA
if the date cannot be converted.
Examples
dates <- c("2025-04-10", "10/04/2025", "April 10, 2025")
converted_dates <- convert_to_date(dates)
print(converted_dates)
[Package Tivy version 0.1.0 Index]