ymd {lubridate} | R Documentation |
Transforms dates stored in character and numeric vectors to POSIXct objects. These functions recognize arbitrary non-digit separators as well as no separator. As long as the order of formats is correct, these functions will parse dates correctly even when the input vectors contain differently formatted dates. See examples.
ymd(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"), truncated = 0)
... |
a character or numeric vector of suspected dates |
quiet |
logical. When TRUE function evalueates without displaying customary messages. |
tz |
Time zone indicator. If NULL (default) a Date object is
returned. Otherwise a POSIXct with time zone attribute set to |
locale |
locale to be used, see locales. On linux systems you
can use |
truncated |
integer. Number of formats that can be truncated. |
ymd
family of functions automatically assign the Universal
Coordinated Time Zone (UTC) to the parsed dates. This time zone can be
changed with force_tz
.
If truncated
parameter is non-zero ymd
functions also check for
truncated formats. For example ymd
with truncated = 2
will also
parse incomplete dates like 2012-06
and 2012
.
NOTE: ymd
family of functions are based on 'parse_date_time' and thus
directly drop to internal C parser for numeric months, but use R's
‘strptime' for alphabetic months. This implies that some of the 'strptime'’s
limitations are inherited by lubridate's parser. For example truncated
formats (like
As of version 1.3.0, lubridate's parse functions no longer return a
message that displays which format they used to parse their input. You can
change this by setting the lubridate.verbose
option to TRUE with
options(lubridate.verbose = TRUE)
.
a vector of class POSIXct if tz argument is non-NULL or Date if tz is NULL (default)
parse_date_time
for an even more flexible low level
mechanism.
x <- c("09-01-01", "09-01-02", "09-01-03") ymd(x) ## "2009-01-01 UTC" "2009-01-02 UTC" "2009-01-03 UTC" x <- c("2009-01-01", "2009-01-02", "2009-01-03") ymd(x) ## "2009-01-01 UTC" "2009-01-02 UTC" "2009-01-03 UTC" ymd(090101, 90102) ## "2009-01-01 UTC" "2009-01-02 UTC" now() > ymd(20090101) ## TRUE dmy(010210) mdy(010210) ## heterogenuous formats in a single vector: x <- c(20090101, "2009-01-02", "2009 01 03", "2009-1-4", "2009-1, 5", "Created on 2009 1 6", "200901 !!! 07") ymd(x) ## What lubridate might not handle: ## Extremely weird cases when one of the separators is "" and some of the ## formats are not in double digits might not be parsed correctly: ## Not run: ymd("201002-01", "201002-1", "20102-1") dmy("0312-2010", "312-2010") ## End(Not run)