year_month | R Documentation |
These are experimental methods for working with year-months and year-quarters inspired by 'zoo' and 'tsibble'.
year_month(x)
year_quarter(x)
YM(length = 0L)
year_month_decimal(x)
decimal_year_month(x)
YQ(length = 0L)
year_quarter_decimal(x)
decimal_year_quarter(x)
x |
A |
length |
Length of |
The biggest difference is that the underlying data is simply
the number of months/quarters since epoch. This makes integer
arithmetic very simple, and allows for fast sequence creation as well as
fast coercion to year_month
and year_quarter
from numeric vectors.
Printing method is also fast.
library(timeplyr)
library(lubridate)
x <- year_month(today())
# Adding 1 adds 1 month
x + 1
# Adding 12 adds 1 year
x + 12
# Sequence of yearmonths
x + 0:12
# If you unclass, do the same arithmetic, and coerce back to year_month
# The result is always the same
year_month(unclass(x) + 1)
year_month(unclass(x) + 12)
# Initialise a year_month or year_quarter to the specified length
YM(0)
YQ(0)
YM(3)
YQ(3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.