which_any_date: Evaluates and gives the possible format(s) for an object to be evaluated
Description
This function takes a character string or a vector. This vector is evaluates
one observation after the other, and gives the best matching date format
for each of them (independently). The best matching format is tested across
seven different formats provided by the lubridate library. The information of
the best matching format can be used to mutate a column using
as_any_date().
A character string of the possible date formats given a parameter to be
tested. The length of the vector is the length of the input object.
Arguments
x
object to be coerced. Can be a character string or a vector.
format
A character identifying the format to apply to the object to
test.
That format can be 'ymd','ydm','dmy','myd','mdy','dym', 'ym', 'my' or
'as_date' in that specific order ('ymd" will be chose as a default format,
then 'ymd', etc.).
Details
Contrary to lubridate library or as.Date(), the function evaluates
the different possibilities for a date. For example, c('02-03-1982') can be
either March the 2nd or February the 3rd. The function will provide
"mdy, dmy" as possible formats. If no format is found, the function returns
NA.
{
time <- c(
"1983-07-19",
"31 jan 2017",
"1988/12/17",
"31-02-05",
"02-02-02",
"2017 october the 2nd",
"02-07-2012",
"19-07-83",
"19-19-19")
which_any_date(time)
}