Align a 'timeDate' object to regular date/time stamps
calendar-align.Rd
Aligns a "timeDate"
object to regular date/time stamps.
Usage
# S4 method for timeDate
align(x, by = "1d", offset = "0s")
alignDaily(x, include.weekends=FALSE)
alignMonthly(x, include.weekends=FALSE)
alignQuarterly(x, include.weekends=FALSE)
Arguments
- x
an object of class
"timeDate"
.- by
a character string formed from an integer length and a period identifier. Valid values are "w", "d", "h", "m", "s", for weeks, days, hours, minutes and seconds. For example a bi-weekly period is expressed as
"2w"
.- offset
a character string to set an offset formed from an integer length and a period identifier in the same way as for argument
by
.- include.weekends
logical value indicating whether weekends should be included.
Details
The functions alignDaily
, alignMonthly
,
alignMonthly
are simple to use functions which
generate end-of-day, end-of-month, and end-of quarter
"timeDate"
objects. Weekends are excluded by
default. Optionally they can be added setting the
argument include.weekends = TRUE
.
Examples
## align -
# Align Bi-Weekly with a 3 Days Offset:
(tC <- timeCalendar())
#> GMT
#> [1] [2023-01-01] [2023-02-01] [2023-03-01] [2023-04-01] [2023-05-01]
#> [6] [2023-06-01] [2023-07-01] [2023-08-01] [2023-09-01] [2023-10-01]
#> [11] [2023-11-01] [2023-12-01]
align(tC, by = "2w", offset = "3d")
#> GMT
#> [1] [2023-01-04] [2023-01-18] [2023-02-01] [2023-02-15] [2023-03-01]
#> [6] [2023-03-15] [2023-03-29] [2023-04-12] [2023-04-26] [2023-05-10]
#> [11] [2023-05-24] [2023-06-07] [2023-06-21] [2023-07-05] [2023-07-19]
#> [16] [2023-08-02] [2023-08-16] [2023-08-30] [2023-09-13] [2023-09-27]
#> [21] [2023-10-11] [2023-10-25] [2023-11-08] [2023-11-22]
## alignDaily -
# Simple to use Functions:
alignDaily(tC)
#> GMT
#> [1] [2023-01-02] [2023-01-03] [2023-01-04] [2023-01-05] [2023-01-06]
#> [6] [2023-01-09] [2023-01-10] [2023-01-11] [2023-01-12] [2023-01-13]
#> [11] [2023-01-16] [2023-01-17] [2023-01-18] [2023-01-19] [2023-01-20]
#> [16] [2023-01-23] [2023-01-24] [2023-01-25] [2023-01-26] [2023-01-27]
#> [21] [2023-01-30] [2023-01-31] [2023-02-01] [2023-02-02] [2023-02-03]
#> [26] [2023-02-06] [2023-02-07] [2023-02-08] [2023-02-09] [2023-02-10]
#> [31] [2023-02-13] [2023-02-14] [2023-02-15] [2023-02-16] [2023-02-17]
#> [36] [2023-02-20] [2023-02-21] [2023-02-22] [2023-02-23] [2023-02-24]
#> [41] [2023-02-27] [2023-02-28] [2023-03-01] [2023-03-02] [2023-03-03]
#> [46] [2023-03-06] [2023-03-07] [2023-03-08] [2023-03-09] [2023-03-10]
#> [51] [2023-03-13] [2023-03-14] [2023-03-15] [2023-03-16] [2023-03-17]
#> [56] [2023-03-20] [2023-03-21] [2023-03-22] [2023-03-23] [2023-03-24]
#> [61] [2023-03-27] [2023-03-28] [2023-03-29] [2023-03-30] [2023-03-31]
#> [66] [2023-04-03] [2023-04-04] [2023-04-05] [2023-04-06] [2023-04-07]
#> [71] [2023-04-10] [2023-04-11] [2023-04-12] [2023-04-13] [2023-04-14]
#> [76] [2023-04-17] [2023-04-18] [2023-04-19] [2023-04-20] [2023-04-21]
#> [81] [2023-04-24] [2023-04-25] [2023-04-26] [2023-04-27] [2023-04-28]
#> [86] [2023-05-01] [2023-05-02] [2023-05-03] [2023-05-04] [2023-05-05]
#> [91] [2023-05-08] [2023-05-09] [2023-05-10] [2023-05-11] [2023-05-12]
#> [96] [2023-05-15] [2023-05-16] [2023-05-17] [2023-05-18] [2023-05-19]
#> ...
#> [ reached getRmetricsOption('max.print') | getOption('max.print') -- omitted 140 rows ]]
alignDaily(tC, include.weekends=TRUE)
#> GMT
#> [1] [2023-01-01] [2023-01-02] [2023-01-03] [2023-01-04] [2023-01-05]
#> [6] [2023-01-06] [2023-01-07] [2023-01-08] [2023-01-09] [2023-01-10]
#> [11] [2023-01-11] [2023-01-12] [2023-01-13] [2023-01-14] [2023-01-15]
#> [16] [2023-01-16] [2023-01-17] [2023-01-18] [2023-01-19] [2023-01-20]
#> [21] [2023-01-21] [2023-01-22] [2023-01-23] [2023-01-24] [2023-01-25]
#> [26] [2023-01-26] [2023-01-27] [2023-01-28] [2023-01-29] [2023-01-30]
#> [31] [2023-01-31] [2023-02-01] [2023-02-02] [2023-02-03] [2023-02-04]
#> [36] [2023-02-05] [2023-02-06] [2023-02-07] [2023-02-08] [2023-02-09]
#> [41] [2023-02-10] [2023-02-11] [2023-02-12] [2023-02-13] [2023-02-14]
#> [46] [2023-02-15] [2023-02-16] [2023-02-17] [2023-02-18] [2023-02-19]
#> [51] [2023-02-20] [2023-02-21] [2023-02-22] [2023-02-23] [2023-02-24]
#> [56] [2023-02-25] [2023-02-26] [2023-02-27] [2023-02-28] [2023-03-01]
#> [61] [2023-03-02] [2023-03-03] [2023-03-04] [2023-03-05] [2023-03-06]
#> [66] [2023-03-07] [2023-03-08] [2023-03-09] [2023-03-10] [2023-03-11]
#> [71] [2023-03-12] [2023-03-13] [2023-03-14] [2023-03-15] [2023-03-16]
#> [76] [2023-03-17] [2023-03-18] [2023-03-19] [2023-03-20] [2023-03-21]
#> [81] [2023-03-22] [2023-03-23] [2023-03-24] [2023-03-25] [2023-03-26]
#> [86] [2023-03-27] [2023-03-28] [2023-03-29] [2023-03-30] [2023-03-31]
#> [91] [2023-04-01] [2023-04-02] [2023-04-03] [2023-04-04] [2023-04-05]
#> [96] [2023-04-06] [2023-04-07] [2023-04-08] [2023-04-09] [2023-04-10]
#> ...
#> [ reached getRmetricsOption('max.print') | getOption('max.print') -- omitted 235 rows ]]
# Align to end-of-month Dates:
alignMonthly(tC)
#> GMT
#> [1] [2023-01-31] [2023-02-28] [2023-03-31] [2023-04-29] [2023-05-31]
#> [6] [2023-06-30] [2023-07-31] [2023-08-31] [2023-09-29] [2023-10-31]
#> [11] [2023-11-30] [2023-12-30]