Skip to contents

Returns start and end dates for rolling periods.

Usage

periods(x, period = "12m", by = "1m", offset = "0d")
periodicallyRolling(x, period = "52w", by = "4w", offset = "0d")
monthlyRolling(x, period = "12m", by = "1m")

Arguments

x

an object of class timeDate.

period

a span string, consisting of a length integer and a unit value, e.g. "52w" for 52 weeks.

by

a span string, consisting of a length integer and a unit value, e.g. "4w" for 4 weeks.

offset

a span string, consisting of a length integer and a unit value, e.g. "0d" for no offset.

Details

Periodically Rolling - Allowed unit values are "m" for 4 weeks, "w" for weeks, "d" for days, "H" for hours, "M" for minutes, and "S" for seconds.

Monthly Calendar Rolling - The only allowed allowed unit value is "m" for monthly periods. Express a quarterly period by "3m", a semester by "6m", a year by "12m" etc.

Examples

## Create Time Sequence -
   x <- timeSequence(from = "2001-01-01", to = "2009-01-01", by = "day")

## Generate Periods -
   periods(x, "12m", "1m")
#> $from
#> GMT
#>  [1] [2001-01-01] [2001-02-01] [2001-03-01] [2001-04-01] [2001-05-01]
#>  [6] [2001-06-01] [2001-07-01] [2001-08-01] [2001-09-01] [2001-10-01]
#> [11] [2001-11-01] [2001-12-01] [2002-01-01] [2002-02-01] [2002-03-01]
#> [16] [2002-04-01] [2002-05-01] [2002-06-01] [2002-07-01] [2002-08-01]
#> [21] [2002-09-01] [2002-10-01] [2002-11-01] [2002-12-01] [2003-01-01]
#> [26] [2003-02-01] [2003-03-01] [2003-04-01] [2003-05-01] [2003-06-01]
#> [31] [2003-07-01] [2003-08-01] [2003-09-01] [2003-10-01] [2003-11-01]
#> [36] [2003-12-01] [2004-01-01] [2004-02-01] [2004-03-01] [2004-04-01]
#> [41] [2004-05-01] [2004-06-01] [2004-07-01] [2004-08-01] [2004-09-01]
#> [46] [2004-10-01] [2004-11-01] [2004-12-01] [2005-01-01] [2005-02-01]
#> [51] [2005-03-01] [2005-04-01] [2005-05-01] [2005-06-01] [2005-07-01]
#> [56] [2005-08-01] [2005-09-01] [2005-10-01] [2005-11-01] [2005-12-01]
#> [61] [2006-01-01] [2006-02-01] [2006-03-01] [2006-04-01] [2006-05-01]
#> [66] [2006-06-01] [2006-07-01] [2006-08-01] [2006-09-01] [2006-10-01]
#> [71] [2006-11-01] [2006-12-01] [2007-01-01] [2007-02-01] [2007-03-01]
#> [76] [2007-04-01] [2007-05-01] [2007-06-01] [2007-07-01] [2007-08-01]
#> [81] [2007-09-01] [2007-10-01] [2007-11-01] [2007-12-01] [2008-01-01]
#> [86] [2008-02-01]
#> 
#> $to
#> GMT
#>  [1] [2001-12-31] [2002-01-31] [2002-02-28] [2002-03-31] [2002-04-30]
#>  [6] [2002-05-31] [2002-06-30] [2002-07-31] [2002-08-31] [2002-09-30]
#> [11] [2002-10-31] [2002-11-30] [2002-12-31] [2003-01-31] [2003-02-28]
#> [16] [2003-03-31] [2003-04-30] [2003-05-31] [2003-06-30] [2003-07-31]
#> [21] [2003-08-31] [2003-09-30] [2003-10-31] [2003-11-30] [2003-12-31]
#> [26] [2004-01-31] [2004-02-29] [2004-03-31] [2004-04-30] [2004-05-31]
#> [31] [2004-06-30] [2004-07-31] [2004-08-31] [2004-09-30] [2004-10-31]
#> [36] [2004-11-30] [2004-12-31] [2005-01-31] [2005-02-28] [2005-03-31]
#> [41] [2005-04-30] [2005-05-31] [2005-06-30] [2005-07-31] [2005-08-31]
#> [46] [2005-09-30] [2005-10-31] [2005-11-30] [2005-12-31] [2006-01-31]
#> [51] [2006-02-28] [2006-03-31] [2006-04-30] [2006-05-31] [2006-06-30]
#> [56] [2006-07-31] [2006-08-31] [2006-09-30] [2006-10-31] [2006-11-30]
#> [61] [2006-12-31] [2007-01-31] [2007-02-28] [2007-03-31] [2007-04-30]
#> [66] [2007-05-31] [2007-06-30] [2007-07-31] [2007-08-31] [2007-09-30]
#> [71] [2007-10-31] [2007-11-30] [2007-12-31] [2008-01-31] [2008-02-29]
#> [76] [2008-03-31] [2008-04-30] [2008-05-31] [2008-06-30] [2008-07-31]
#> [81] [2008-08-31] [2008-09-30] [2008-10-31] [2008-11-30] [2008-12-31]
#> [86] [2009-01-31]
#> 
#> attr(,"control")
#> GMT
#>        start          end 
#> [2001-01-01] [2009-01-01] 
   periods(x, "52w", "4w")
#> $from
#> GMT
#>  [1] [2001-01-01] [2001-01-29] [2001-02-26] [2001-03-26] [2001-04-23]
#>  [6] [2001-05-21] [2001-06-18] [2001-07-16] [2001-08-13] [2001-09-10]
#> [11] [2001-10-08] [2001-11-05] [2001-12-03] [2001-12-31] [2002-01-28]
#> [16] [2002-02-25] [2002-03-25] [2002-04-22] [2002-05-20] [2002-06-17]
#> [21] [2002-07-15] [2002-08-12] [2002-09-09] [2002-10-07] [2002-11-04]
#> [26] [2002-12-02] [2002-12-30] [2003-01-27] [2003-02-24] [2003-03-24]
#> [31] [2003-04-21] [2003-05-19] [2003-06-16] [2003-07-14] [2003-08-11]
#> [36] [2003-09-08] [2003-10-06] [2003-11-03] [2003-12-01] [2003-12-29]
#> [41] [2004-01-26] [2004-02-23] [2004-03-22] [2004-04-19] [2004-05-17]
#> [46] [2004-06-14] [2004-07-12] [2004-08-09] [2004-09-06] [2004-10-04]
#> [51] [2004-11-01] [2004-11-29] [2004-12-27] [2005-01-24] [2005-02-21]
#> [56] [2005-03-21] [2005-04-18] [2005-05-16] [2005-06-13] [2005-07-11]
#> [61] [2005-08-08] [2005-09-05] [2005-10-03] [2005-10-31] [2005-11-28]
#> [66] [2005-12-26] [2006-01-23] [2006-02-20] [2006-03-20] [2006-04-17]
#> [71] [2006-05-15] [2006-06-12] [2006-07-10] [2006-08-07] [2006-09-04]
#> [76] [2006-10-02] [2006-10-30] [2006-11-27] [2006-12-25] [2007-01-22]
#> [81] [2007-02-19] [2007-03-19] [2007-04-16] [2007-05-14] [2007-06-11]
#> [86] [2007-07-09] [2007-08-06] [2007-09-03] [2007-10-01] [2007-10-29]
#> [91] [2007-11-26] [2007-12-24]
#> 
#> $to
#> GMT
#>  [1] [2001-12-31] [2002-01-28] [2002-02-25] [2002-03-25] [2002-04-22]
#>  [6] [2002-05-20] [2002-06-17] [2002-07-15] [2002-08-12] [2002-09-09]
#> [11] [2002-10-07] [2002-11-04] [2002-12-02] [2002-12-30] [2003-01-27]
#> [16] [2003-02-24] [2003-03-24] [2003-04-21] [2003-05-19] [2003-06-16]
#> [21] [2003-07-14] [2003-08-11] [2003-09-08] [2003-10-06] [2003-11-03]
#> [26] [2003-12-01] [2003-12-29] [2004-01-26] [2004-02-23] [2004-03-22]
#> [31] [2004-04-19] [2004-05-17] [2004-06-14] [2004-07-12] [2004-08-09]
#> [36] [2004-09-06] [2004-10-04] [2004-11-01] [2004-11-29] [2004-12-27]
#> [41] [2005-01-24] [2005-02-21] [2005-03-21] [2005-04-18] [2005-05-16]
#> [46] [2005-06-13] [2005-07-11] [2005-08-08] [2005-09-05] [2005-10-03]
#> [51] [2005-10-31] [2005-11-28] [2005-12-26] [2006-01-23] [2006-02-20]
#> [56] [2006-03-20] [2006-04-17] [2006-05-15] [2006-06-12] [2006-07-10]
#> [61] [2006-08-07] [2006-09-04] [2006-10-02] [2006-10-30] [2006-11-27]
#> [66] [2006-12-25] [2007-01-22] [2007-02-19] [2007-03-19] [2007-04-16]
#> [71] [2007-05-14] [2007-06-11] [2007-07-09] [2007-08-06] [2007-09-03]
#> [76] [2007-10-01] [2007-10-29] [2007-11-26] [2007-12-24] [2008-01-21]
#> [81] [2008-02-18] [2008-03-17] [2008-04-14] [2008-05-12] [2008-06-09]
#> [86] [2008-07-07] [2008-08-04] [2008-09-01] [2008-09-29] [2008-10-27]
#> [91] [2008-11-24] [2008-12-22]
#> 
#> attr(,"control")
#> GMT
#>        start          end 
#> [2001-01-01] [2009-01-01] 

## Roll Periodically -
   periodicallyRolling(x)
#> $from
#> GMT
#>  [1] [2001-01-01] [2001-01-29] [2001-02-26] [2001-03-26] [2001-04-23]
#>  [6] [2001-05-21] [2001-06-18] [2001-07-16] [2001-08-13] [2001-09-10]
#> [11] [2001-10-08] [2001-11-05] [2001-12-03] [2001-12-31] [2002-01-28]
#> [16] [2002-02-25] [2002-03-25] [2002-04-22] [2002-05-20] [2002-06-17]
#> [21] [2002-07-15] [2002-08-12] [2002-09-09] [2002-10-07] [2002-11-04]
#> [26] [2002-12-02] [2002-12-30] [2003-01-27] [2003-02-24] [2003-03-24]
#> [31] [2003-04-21] [2003-05-19] [2003-06-16] [2003-07-14] [2003-08-11]
#> [36] [2003-09-08] [2003-10-06] [2003-11-03] [2003-12-01] [2003-12-29]
#> [41] [2004-01-26] [2004-02-23] [2004-03-22] [2004-04-19] [2004-05-17]
#> [46] [2004-06-14] [2004-07-12] [2004-08-09] [2004-09-06] [2004-10-04]
#> [51] [2004-11-01] [2004-11-29] [2004-12-27] [2005-01-24] [2005-02-21]
#> [56] [2005-03-21] [2005-04-18] [2005-05-16] [2005-06-13] [2005-07-11]
#> [61] [2005-08-08] [2005-09-05] [2005-10-03] [2005-10-31] [2005-11-28]
#> [66] [2005-12-26] [2006-01-23] [2006-02-20] [2006-03-20] [2006-04-17]
#> [71] [2006-05-15] [2006-06-12] [2006-07-10] [2006-08-07] [2006-09-04]
#> [76] [2006-10-02] [2006-10-30] [2006-11-27] [2006-12-25] [2007-01-22]
#> [81] [2007-02-19] [2007-03-19] [2007-04-16] [2007-05-14] [2007-06-11]
#> [86] [2007-07-09] [2007-08-06] [2007-09-03] [2007-10-01] [2007-10-29]
#> [91] [2007-11-26] [2007-12-24]
#> 
#> $to
#> GMT
#>  [1] [2001-12-31] [2002-01-28] [2002-02-25] [2002-03-25] [2002-04-22]
#>  [6] [2002-05-20] [2002-06-17] [2002-07-15] [2002-08-12] [2002-09-09]
#> [11] [2002-10-07] [2002-11-04] [2002-12-02] [2002-12-30] [2003-01-27]
#> [16] [2003-02-24] [2003-03-24] [2003-04-21] [2003-05-19] [2003-06-16]
#> [21] [2003-07-14] [2003-08-11] [2003-09-08] [2003-10-06] [2003-11-03]
#> [26] [2003-12-01] [2003-12-29] [2004-01-26] [2004-02-23] [2004-03-22]
#> [31] [2004-04-19] [2004-05-17] [2004-06-14] [2004-07-12] [2004-08-09]
#> [36] [2004-09-06] [2004-10-04] [2004-11-01] [2004-11-29] [2004-12-27]
#> [41] [2005-01-24] [2005-02-21] [2005-03-21] [2005-04-18] [2005-05-16]
#> [46] [2005-06-13] [2005-07-11] [2005-08-08] [2005-09-05] [2005-10-03]
#> [51] [2005-10-31] [2005-11-28] [2005-12-26] [2006-01-23] [2006-02-20]
#> [56] [2006-03-20] [2006-04-17] [2006-05-15] [2006-06-12] [2006-07-10]
#> [61] [2006-08-07] [2006-09-04] [2006-10-02] [2006-10-30] [2006-11-27]
#> [66] [2006-12-25] [2007-01-22] [2007-02-19] [2007-03-19] [2007-04-16]
#> [71] [2007-05-14] [2007-06-11] [2007-07-09] [2007-08-06] [2007-09-03]
#> [76] [2007-10-01] [2007-10-29] [2007-11-26] [2007-12-24] [2008-01-21]
#> [81] [2008-02-18] [2008-03-17] [2008-04-14] [2008-05-12] [2008-06-09]
#> [86] [2008-07-07] [2008-08-04] [2008-09-01] [2008-09-29] [2008-10-27]
#> [91] [2008-11-24] [2008-12-22]
#> 
#> attr(,"control")
#> GMT
#>        start          end 
#> [2001-01-01] [2009-01-01] 

## Roll Monthly -
   monthlyRolling(x)
#> $from
#> GMT
#>  [1] [2001-01-01] [2001-02-01] [2001-03-01] [2001-04-01] [2001-05-01]
#>  [6] [2001-06-01] [2001-07-01] [2001-08-01] [2001-09-01] [2001-10-01]
#> [11] [2001-11-01] [2001-12-01] [2002-01-01] [2002-02-01] [2002-03-01]
#> [16] [2002-04-01] [2002-05-01] [2002-06-01] [2002-07-01] [2002-08-01]
#> [21] [2002-09-01] [2002-10-01] [2002-11-01] [2002-12-01] [2003-01-01]
#> [26] [2003-02-01] [2003-03-01] [2003-04-01] [2003-05-01] [2003-06-01]
#> [31] [2003-07-01] [2003-08-01] [2003-09-01] [2003-10-01] [2003-11-01]
#> [36] [2003-12-01] [2004-01-01] [2004-02-01] [2004-03-01] [2004-04-01]
#> [41] [2004-05-01] [2004-06-01] [2004-07-01] [2004-08-01] [2004-09-01]
#> [46] [2004-10-01] [2004-11-01] [2004-12-01] [2005-01-01] [2005-02-01]
#> [51] [2005-03-01] [2005-04-01] [2005-05-01] [2005-06-01] [2005-07-01]
#> [56] [2005-08-01] [2005-09-01] [2005-10-01] [2005-11-01] [2005-12-01]
#> [61] [2006-01-01] [2006-02-01] [2006-03-01] [2006-04-01] [2006-05-01]
#> [66] [2006-06-01] [2006-07-01] [2006-08-01] [2006-09-01] [2006-10-01]
#> [71] [2006-11-01] [2006-12-01] [2007-01-01] [2007-02-01] [2007-03-01]
#> [76] [2007-04-01] [2007-05-01] [2007-06-01] [2007-07-01] [2007-08-01]
#> [81] [2007-09-01] [2007-10-01] [2007-11-01] [2007-12-01] [2008-01-01]
#> [86] [2008-02-01]
#> 
#> $to
#> GMT
#>  [1] [2001-12-31] [2002-01-31] [2002-02-28] [2002-03-31] [2002-04-30]
#>  [6] [2002-05-31] [2002-06-30] [2002-07-31] [2002-08-31] [2002-09-30]
#> [11] [2002-10-31] [2002-11-30] [2002-12-31] [2003-01-31] [2003-02-28]
#> [16] [2003-03-31] [2003-04-30] [2003-05-31] [2003-06-30] [2003-07-31]
#> [21] [2003-08-31] [2003-09-30] [2003-10-31] [2003-11-30] [2003-12-31]
#> [26] [2004-01-31] [2004-02-29] [2004-03-31] [2004-04-30] [2004-05-31]
#> [31] [2004-06-30] [2004-07-31] [2004-08-31] [2004-09-30] [2004-10-31]
#> [36] [2004-11-30] [2004-12-31] [2005-01-31] [2005-02-28] [2005-03-31]
#> [41] [2005-04-30] [2005-05-31] [2005-06-30] [2005-07-31] [2005-08-31]
#> [46] [2005-09-30] [2005-10-31] [2005-11-30] [2005-12-31] [2006-01-31]
#> [51] [2006-02-28] [2006-03-31] [2006-04-30] [2006-05-31] [2006-06-30]
#> [56] [2006-07-31] [2006-08-31] [2006-09-30] [2006-10-31] [2006-11-30]
#> [61] [2006-12-31] [2007-01-31] [2007-02-28] [2007-03-31] [2007-04-30]
#> [66] [2007-05-31] [2007-06-30] [2007-07-31] [2007-08-31] [2007-09-30]
#> [71] [2007-10-31] [2007-11-30] [2007-12-31] [2008-01-31] [2008-02-29]
#> [76] [2008-03-31] [2008-04-30] [2008-05-31] [2008-06-30] [2008-07-31]
#> [81] [2008-08-31] [2008-09-30] [2008-10-31] [2008-11-30] [2008-12-31]
#> [86] [2009-01-31]
#> 
#> attr(,"control")
#> GMT
#>        start          end 
#> [2001-01-01] [2009-01-01]