std_date standardizes a date vector and returns a vector in Date or
POSIXct format, depending on whether there is sub-daily information
available in the data.
Usage
std_date(
x,
force = c("none", "dt", "dttm"),
orders = c("mdy", "dmy", "ymd", "mdyr", "dmyr", "ymdr", "mdyR", "dmyR", "ymdR", "mdyT",
"dmyT", "ymdT", "mdyTz", "dmyTz", "ymdTz", "Tmdyz", "Tdmyz", "Tymdz", "mdyRz",
"dmyRz", "ymdRz", "mdyrz", "dmyrz", "ymdrz", "Tmdy", "Tdmy", "Tymd", "Tmdyz",
"Tdmyz", "Tymdz"),
tz_heuristic = c(5L, 6L),
warn = TRUE,
train = TRUE,
na = na_patterns,
range_value = c("start", "end", "na"),
range_sep = c("-", "to", ","),
...
)Arguments
- x
A vector of
characterdates,Dates, orPOSIXts- force
Whether to force conversion to
Date(force = "dt") orPOSIXct(force = "dttm"). The default is no forcing (force = "none").- orders
A
charactervector of date-time formats. Each order string is a series of formatting characters as listed inbase::strptime()but might not include the "%" prefix. For example, "ymd" will match all the possible dates in year, month, day order. Formatting orders might include arbitrary separators. These are discarded. See details oflubridate::parse_date_time()for the implemented formats. If multiple order strings are supplied, the order of applied formats is determined by theselect_formatsparameter inlubridate::parse_date_time()(if passed via dots).- tz_heuristic
Hours to consider in determining presence of sub-daily information. Only exact hours (i.e. 5:00:00) will be combined. The default corresponds to accidental encoding of the CST-UTC offset as hours.
- warn
Should warnings be thrown when necessary?
FALSEwill suppress all warnings in the conversion process.- train
logical, defaultTRUE. Whether to train formats on a subset of the input vector. The result of this is that supplied orders are sorted according to performance on this training set, which commonly results in increased performance. Please note that even whentrain = FALSE(andexact = FALSE, if passed via dots) guessing of the actual formats is still performed on a pseudo-random subset of the original input vector. This might result inAll formats failed to parse error.See notes inlubridate::parse_date_time().- na
Regular expressions to convert to
NA- range_value
The value to use if the date is given as a range; can be the start date, the end date, or fill with
NA- range_sep
Separators used for date ranges
- ...
Additional arguments to pass to
convert_to_datetime(). These will, in turn, be passed to further methods, includingexcel_numeric_to_date(),parse_date_time(), andas.POSIXct().