messydate {messydates} | R Documentation |
Coercion from regular date classes to mdate
Description
These methods coerce various date classes into the mdate
class.
They represent the main user-facing class-creating functions in the package.
In addition to the typical date classes in R (Date
, POSIXct
, and POSIXlt
),
there is also a direct method for converting text or character strings to mdate
.
The function can also extract dates from text,
though this is a work-in-progress and currently only works in English.
Usage
as_messydate(x, resequence = FALSE)
## S3 method for class 'Date'
as_messydate(x, resequence = FALSE)
## S3 method for class 'POSIXct'
as_messydate(x, resequence = FALSE)
## S3 method for class 'POSIXlt'
as_messydate(x, resequence = FALSE)
## S3 method for class 'character'
as_messydate(x, resequence = NULL)
## S3 method for class 'list'
as_messydate(x, resequence = FALSE)
mdate(x, resequence = FALSE)
make_messydate(..., resequence = FALSE)
Arguments
x |
A scalar or vector of a class that can be coerced into |
resequence |
Users have the option to choose the order for
ambiguous dates with or without separators (e.g. "11-01-12" or "20112112").
|
... |
One (yyyy-mm-dd), two (yyyy-mm-dd, yyyy-mm-dd), or three (yyyy, mm, dd) variables. |
Details
If three date variables are passed to make_messydate()
,
function will create a single date (yyyy-mm-dd) from it.
If two date variables are passed to make_messydate()
,
function will create a range of dates from it (yyyy-mm-dd..yyyy-mm-dd).
If one date variable is passed to make_messydate()
,
function defaults to as_messydate()
.
Value
A mdate
class object
Functions
-
as_messydate()
: Coremdate
class coercion function -
as_messydate(Date)
: Coerce fromDate
tomdate
class -
as_messydate(POSIXct)
: Coerce fromPOSIXct
tomdate
class -
as_messydate(POSIXlt)
: Coerce fromPOSIXlt
tomdate
class -
as_messydate(character)
: Coerce character date objects tomdate
class -
as_messydate(list)
: Coerce list date objects to the most concise representation ofmdate
class -
make_messydate()
: Composesmdate
from multiple variables
Examples
as_messydate("2021")
as_messydate("2021-02")
as_messydate("2021-02-01")
as_messydate("01-02-2021")
as_messydate("1 February 2021")
as_messydate("First of February, two thousand and twenty-one")
as_messydate("2021-02-01?")
as_messydate("2021-02-01~")
as_messydate("2021-02-01%")
as_messydate("2021-02-01..2021-02-28")
as_messydate("{2021-02-01,2021-02-28}")
as_messydate(c("-2021", "2021 BC", "-2021-02-01"))
as_messydate(c("210201", "20210201"), resequence = "ymd")
as_messydate(c("010221", "01022021"), resequence = "dmy")
# as_messydate(c("01-02-21", "01-02-2021", "01-02-91", "01-02-1991"),
# resequence = "interactive")
as_messydate(list(c("2012-06-01", "2012-06-02", "2012-06-03")))
as_messydate(list(c("2012-06-01", "2012-06-02", "2012-06-03",
"{2012-06-01, 2012-06-02, 2012-06-03}", "2012-06-01", "2012-06-03")))
make_messydate("2010", "10", "10")