Flexible time vectors for R
GPL-3.0 License
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
mixtime provides flexible time classes for representing mixed temporal granularities and custom calendar structures.
The feature wishlist for this package includes:
Stretch goals for the package include:
time_join()
operation which respects temporal nestingThe development version can be installed from GitHub with:
# install.packages("devtools")
devtools::install_github("mitchelloharawild/mixtime")
Creating mixtimes.
library(mixtime)
yearmonth(0:11) # By default, time classes have an origin
yearmonth(0:11) - yearmonth(0) # However some operations can produce mixtimes without origins
yearquarter(0:3)
yearquarter(0:3) - yearquarter(0)
# Different temporal granularities can be combined:
c(yearquarter(0:3), yearmonth(0:11))
Sequences of mixtimes.
seq(yearmonth(0), yearmonth(10), by = 1)
Integration with tsibble.
tsibble::tsibble(time = yearmonth(0:5), index = time)
tsibble::tsibble(time = c(year(0), yearquarter(0:3), yearmonth(0:5), Sys.Date()), index = time)
Change granularities by updating the calendar.
x <- yearmonth(0:11)
tsibble::tsibble(
yearmonth = x,
yearquarter = set_time_units(x, tu_quarter(1)),
year = set_time_units(x, tu_year(1)),
index = yearmonth
)