which_any_date {fabR}R Documentation

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().

Usage

which_any_date(
  x,
  format = c("ymd", "ydm", "dmy", "myd", "mdy", "dym", "my", "ym", "as_date")
)

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.

Value

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.

See Also

lubridate::ymd(),lubridate::ydm(),lubridate::dmy(), lubridate::myd(),lubridate::mdy(),lubridate::dym(), lubridate::my() ,lubridate::ym(), lubridate::as_date(),as.Date(), guess_date_format(),as_any_date()

Examples

{

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)

}


[Package fabR version 2.1.0 Index]