| coerce_from | R Documentation |
mdate to common date classesThese functions coerce objects of mdate class to
common date classes such as Date, POSIXct, and POSIXlt.
Since mdate objects can hold multiple individual dates, however,
an additional function must be passed as an argument so that
these functions know how to resolve multiple dates into a single date.
For example, one might wish to use the earliest possible date
in any ranges of dates (min), the latest possible date (max),
some notion of a central tendency (mean, median, or modal),
or even a random selection from among the candidate dates.
These functions then, building on compatible_dates() and the resolve functions,
are particularly useful in converting back out of the mdate class
for use with existing methods and models,
especially for checking the robustness of results.
## S3 method for class 'mdate'
as.Date(x, FUN, ...)
## S3 method for class 'mdate'
as.POSIXct(x, tz = "UTC", FUN, ...)
## S3 method for class 'mdate'
as.POSIXlt(x, tz = "UTC", FUN, ...)
## S3 method for class 'mdate'
as.data.frame(x, ...)
## S3 method for class 'mdate'
as.double(x, FUN, ...)
## S4 method for signature 'mdate'
as_datetime(x, ...)
x |
A |
FUN |
A function that can be used to resolve expanded messy dates
into a single date.
For example, A precise value needs no |
... |
Arguments passed on to the S3 generics. |
tz |
Character string specifying the time zone for the conversion, if required. By default "UTC" (Universal Time Coordinated), equivalent to GMT. If "" then the current time zone is used. |
as.Date() always drops any time of day carried by x (a calendar
date has no time component); use as.POSIXct() or as.POSIXlt() to
keep the time.
as.POSIXct() and as.POSIXlt() keep the time of day (defaulting to
midnight if x is date-only), and honour a UTC offset if x carries
one. They do not support dates before the common era; use as.Date()
for those.
as.data.frame() places the (unresolved) mdate vector in a
single-column data frame, as for any other vector.
as.double() converts x to the number of days since 1970-01-01,
as as.double(as.Date(x, FUN)) does.
An imprecise value is first resolved with FUN, as for as.Date().
{lubridate}'s as_date() and as_datetime() also accept an mdate
(delegating to as.Date()/as.POSIXct() above, so the FUN resolver
still applies).
A date object of Date, POSIXct, or POSIXlt class
resolve_extrema(), resolve_tendency(), resolve_probabilistically()
Other coerce:
coerce_to
as.Date(as_messydate("2012-01"), FUN = vmin)
as.Date(as_messydate("2012-01-01"), FUN = vmean)
as.Date(as_messydate("2012-01"), FUN = vmax)
as.Date(as_messydate("2012-01"), FUN = vmedian)
as.Date(as_messydate("2012-01"), FUN = vmodal)
as.Date(as_messydate("2012-01"), FUN = vrandom)
# "1000 BC" is the astronomical year -0999 (year zero exists), whereas the
# signed ISO "-1000" below is astronomical year -1000
as.Date(as_messydate("1000 BC"), FUN = vmax)
as.Date(as_messydate("1000 BC"), FUN = vmedian)
as.Date(as_messydate(c("-1000", "2020")), FUN = vmin)
# the time of day, if any, is dropped
as.Date(as_messydate("2012-01-01 14:30"), FUN = vmin)
as.POSIXct(as_messydate("2012-01-01 14:30:00"), FUN = vmin)
as.POSIXct(as_messydate("2012-01-01 14:30:00+02:00"), FUN = vmin)
as.POSIXlt(as_messydate("2012-01-01 14:30:00"), FUN = vmin)
as.data.frame(as_messydate(c("2012-01-01", "2012-02")))
as.double(as_messydate("2012-01-01"))
as.double(as_messydate("2012-01"), FUN = vmax)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.