year_month {timeplyr} | R Documentation |
Fast methods for creating year-months and year-quarters
Description
These are experimental methods for working with year-months and year-quarters inspired by 'zoo' and 'tsibble'.
Usage
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)
Arguments
x |
A |
length |
Length of |
Details
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.
Examples
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)
[Package timeplyr version 0.8.1 Index]