guess_format
From lubridate v0.1
by Hadley Wickham
Guess the format of dates in a character or numeric vector...
Guess the format of dates in a character or numeric vector
- Keywords
- chron
Usage
guess_format(x, formats, seps=c("-", "/", ""))
Arguments
- x
- a character or numeric vector of suspected dates
- formats
- a list of formats to test. Each format should be a vector of
date-time format elements. To test an alternative order of elements, the
alternative order should be entered as an additional format. See
link[base]{strptime}
for format elements. - seps
- a vector of possible characters used to separate elements within the dates.
Details
Returns the format that successfully parses the most dates within a character or numeric vector to POSIXct objects. If multiple formats are equally successful, guess format will display the successful formats in a message and select the first format by default. guess_format assumes that each date only uses one type of separator and that all dates use the same separator.
Value
- a character string of the most likely date-time format
See Also
Examples
x <- c("2009/01/01", "2009/01/02", "2009/01/03")
guess_format(x, list(c("%y", "%m", "%d"), c("%Y", "%m", "%d")), seps = c("-", "", "/"))
# "\%Y/\%m/\%d"
x <- c("20090101", "20090102", "20090103")
guess_format(x, list(c("%y", "%m", "%d"), c("%Y", "%m", "%d")), seps = c("-", "", "/"))
# "\%Y\%m\%d"
x <- c("09-01-01", "09-01-02", "09-01-03")
guess_format(x, list(c("%y", "%m", "%d"), c("%Y", "%m", "%d")), seps = c("-", "", "/"))
# Multiple format matches with 3 successes: \%y-\%m-\%d, \%Y-\%m-\%d.
# 1
# "\%y-\%m-\%d"}
Community examples
Looks like there are no examples yet.