yearmonth_class | R Documentation |
<grates_yearmonth>
objects represent, unsurprisingly, years and associated months.
Internally they are stored as the number of months (starting at 0) since the
Unix Epoch (1970-01-01). Precision is only to the month level (i.e. the day
of the month is always dropped).
yearmonth(year = integer(), month = integer())
as_yearmonth(x, ...)
## Default S3 method:
as_yearmonth(x, ...)
## S3 method for class 'Date'
as_yearmonth(x, ...)
## S3 method for class 'POSIXt'
as_yearmonth(x, ...)
## S3 method for class 'character'
as_yearmonth(x, ...)
## S3 method for class 'factor'
as_yearmonth(x, ...)
new_yearmonth(x = integer())
is_yearmonth(xx)
year |
Vector representing the year associated with
|
month |
Vector representing the month associated with
|
x , xx |
R objects. |
... |
Only used for character input where additional arguments are passed through
to |
yearmonth()
is a constructor for <grates_yearmonth>
objects. It takes a
vector of year and a vector of month values as inputs. Length 1 inputs will
be recycled to the length of the other input and double
vectors will
be converted to integer via as.integer(floor(x))
.
as_yearmonth()
is a generic for coercing input in to <grates_yearmonth>
.
Character input is first parsed using as.Date()
.
POSIXct and POSIXlt are converted with their timezone respected.
new_yearmonth()
is a minimal constructor for <grates_yearmonth>
objects
aimed at developers. It takes, as input, the number of months (starting at 0)
since the Unix Epoch, that you wish to represent. double
vectors will again
be converted to integer via as.integer(floor(x))
.
A <grates_yearmonth>
object.
The algorithm to convert between dates and months relative to the UNIX Epoch comes from the work of Davis Vaughan in the unreleased datea package
new_month()
and as_month()
and for grouping of consecutive months.
# date coercion
as_yearmonth(Sys.Date())
# POSIXt coercion
as_yearmonth(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"))
# character coercion
as_yearmonth("2019-05-03")
# construction
yearmonth(year = 2000, month = 3)
# direct construction
d <- seq.Date(from = as.Date("1970-01-01"), by = "month", length.out = 10)
stopifnot(
identical(
as_yearmonth(d),
new_yearmonth(0:9)
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.