
Expand a time_period
vector to the full range of possible times
Source: R/periodic-times.R
date_seq.time_period.Rd
Derive from a vector of observation time_periods
, a complete ordered sequence of
periods in a regular time series, where the length of the periods is
specified, as a number of days, weeks, years etc. E.g. this can convert a
random set of times to a ordered complete list of 1 week intervals (or 2
month intervals) spanning the same range as the dates. This has some
interesting problems regarding where to put breaks within a month or week.
Often this is either based on a specific date (e.g. yearly periods starting
at 2020-01-01
) or a day of week (e.g. 2 weekly periods staring on a sunday)
or maybe relative to the input time series (weekly ending on the last date of
the data). There is also a problem when we consider data that may have
incomplete starting and end periods, which may not be comparable to other
periods, and we may need to exclude these from the result.
Usage
# S3 method for class 'time_period'
date_seq(x, period = attributes(x)$unit, complete = FALSE, ...)
Value
a vector of time_periods
for regular periods between the minimum and maximum of
dates, with the boundaries defined by the anchor.
Examples
tmp = as.time_period(c(0,10,100), 7, "2020-01-01")
date_seq(tmp, "7 days")
#> time unit: week, origin: 2020-01-01 (a Wednesday)
#> [1] 0 10 20 30 40 50 60 70 80 90 100
date_seq(tmp, "1 day")
#> time unit: week, origin: 2020-01-01 (a Wednesday)
#> [1] 0.1428571 0.2857143 0.4285714 0.5714286 0.7142857 0.8571429
#> [7] 1.0000000 1.1428571 1.2857143 1.4285714 1.5714286 1.7142857
#> [13] 1.8571429 2.0000000 2.1428571 2.2857143 2.4285714 2.5714286
#> [19] 2.7142857 2.8571429 3.0000000 3.1428571 3.2857143 3.4285714
#> [25] 3.5714286 3.7142857 3.8571429 4.0000000 4.1428571 4.2857143
#> [31] 4.4285714 4.5714286 4.7142857 4.8571429 5.0000000 5.1428571
#> [37] 5.2857143 5.4285714 5.5714286 5.7142857 5.8571429 6.0000000
#> [43] 6.1428571 6.2857143 6.4285714 6.5714286 6.7142857 6.8571429
#> [49] 7.0000000 7.1428571 7.2857143 7.4285714 7.5714286 7.7142857
#> [55] 7.8571429 8.0000000 8.1428571 8.2857143 8.4285714 8.5714286
#> [61] 8.7142857 8.8571429 9.0000000 9.1428571 9.2857143 9.4285714
#> [67] 9.5714286 9.7142857 9.8571429 10.0000000 10.1428571 10.2857143
#> [73] 10.4285714 10.5714286 10.7142857 10.8571429 11.0000000 11.1428571
#> [79] 11.2857143 11.4285714 11.5714286 11.7142857 11.8571429 12.0000000
#> [85] 12.1428571 12.2857143 12.4285714 12.5714286 12.7142857 12.8571429
#> [91] 13.0000000 13.1428571 13.2857143 13.4285714 13.5714286 13.7142857
#> [97] 13.8571429 14.0000000 14.1428571 14.2857143 14.4285714 14.5714286
#> [103] 14.7142857 14.8571429 15.0000000 15.1428571 15.2857143 15.4285714
#> [109] 15.5714286 15.7142857 15.8571429 16.0000000 16.1428571 16.2857143
#> [115] 16.4285714 16.5714286 16.7142857 16.8571429 17.0000000 17.1428571
#> [121] 17.2857143 17.4285714 17.5714286 17.7142857 17.8571429 18.0000000
#> [127] 18.1428571 18.2857143 18.4285714 18.5714286 18.7142857 18.8571429
#> [133] 19.0000000 19.1428571 19.2857143 19.4285714 19.5714286 19.7142857
#> [139] 19.8571429 20.0000000 20.1428571 20.2857143 20.4285714 20.5714286
#> [145] 20.7142857 20.8571429 21.0000000 21.1428571 21.2857143 21.4285714
#> [151] 21.5714286 21.7142857 21.8571429 22.0000000 22.1428571 22.2857143
#> [157] 22.4285714 22.5714286 22.7142857 22.8571429 23.0000000 23.1428571
#> [163] 23.2857143 23.4285714 23.5714286 23.7142857 23.8571429 24.0000000
#> [169] 24.1428571 24.2857143 24.4285714 24.5714286 24.7142857 24.8571429
#> [175] 25.0000000 25.1428571 25.2857143 25.4285714 25.5714286 25.7142857
#> [181] 25.8571429 26.0000000 26.1428571 26.2857143 26.4285714 26.5714286
#> [187] 26.7142857 26.8571429 27.0000000 27.1428571 27.2857143 27.4285714
#> [193] 27.5714286 27.7142857 27.8571429 28.0000000 28.1428571 28.2857143
#> [199] 28.4285714 28.5714286 28.7142857 28.8571429 29.0000000 29.1428571
#> [205] 29.2857143 29.4285714 29.5714286 29.7142857 29.8571429 30.0000000
#> [211] 30.1428571 30.2857143 30.4285714 30.5714286 30.7142857 30.8571429
#> [217] 31.0000000 31.1428571 31.2857143 31.4285714 31.5714286 31.7142857
#> [223] 31.8571429 32.0000000 32.1428571 32.2857143 32.4285714 32.5714286
#> [229] 32.7142857 32.8571429 33.0000000 33.1428571 33.2857143 33.4285714
#> [235] 33.5714286 33.7142857 33.8571429 34.0000000 34.1428571 34.2857143
#> [241] 34.4285714 34.5714286 34.7142857 34.8571429 35.0000000 35.1428571
#> [247] 35.2857143 35.4285714 35.5714286 35.7142857 35.8571429 36.0000000
#> [253] 36.1428571 36.2857143 36.4285714 36.5714286 36.7142857 36.8571429
#> [259] 37.0000000 37.1428571 37.2857143 37.4285714 37.5714286 37.7142857
#> [265] 37.8571429 38.0000000 38.1428571 38.2857143 38.4285714 38.5714286
#> [271] 38.7142857 38.8571429 39.0000000 39.1428571 39.2857143 39.4285714
#> [277] 39.5714286 39.7142857 39.8571429 40.0000000 40.1428571 40.2857143
#> [283] 40.4285714 40.5714286 40.7142857 40.8571429 41.0000000 41.1428571
#> [289] 41.2857143 41.4285714 41.5714286 41.7142857 41.8571429 42.0000000
#> [295] 42.1428571 42.2857143 42.4285714 42.5714286 42.7142857 42.8571429
#> [301] 43.0000000 43.1428571 43.2857143 43.4285714 43.5714286 43.7142857
#> [307] 43.8571429 44.0000000 44.1428571 44.2857143 44.4285714 44.5714286
#> [313] 44.7142857 44.8571429 45.0000000 45.1428571 45.2857143 45.4285714
#> [319] 45.5714286 45.7142857 45.8571429 46.0000000 46.1428571 46.2857143
#> [325] 46.4285714 46.5714286 46.7142857 46.8571429 47.0000000 47.1428571
#> [331] 47.2857143 47.4285714 47.5714286 47.7142857 47.8571429 48.0000000
#> [337] 48.1428571 48.2857143 48.4285714 48.5714286 48.7142857 48.8571429
#> [343] 49.0000000 49.1428571 49.2857143 49.4285714 49.5714286 49.7142857
#> [349] 49.8571429 50.0000000 50.1428571 50.2857143 50.4285714 50.5714286
#> [355] 50.7142857 50.8571429 51.0000000 51.1428571 51.2857143 51.4285714
#> [361] 51.5714286 51.7142857 51.8571429 52.0000000 52.1428571 52.2857143
#> [367] 52.4285714 52.5714286 52.7142857 52.8571429 53.0000000 53.1428571
#> [373] 53.2857143 53.4285714 53.5714286 53.7142857 53.8571429 54.0000000
#> [379] 54.1428571 54.2857143 54.4285714 54.5714286 54.7142857 54.8571429
#> [385] 55.0000000 55.1428571 55.2857143 55.4285714 55.5714286 55.7142857
#> [391] 55.8571429 56.0000000 56.1428571 56.2857143 56.4285714 56.5714286
#> [397] 56.7142857 56.8571429 57.0000000 57.1428571 57.2857143 57.4285714
#> [403] 57.5714286 57.7142857 57.8571429 58.0000000 58.1428571 58.2857143
#> [409] 58.4285714 58.5714286 58.7142857 58.8571429 59.0000000 59.1428571
#> [415] 59.2857143 59.4285714 59.5714286 59.7142857 59.8571429 60.0000000
#> [421] 60.1428571 60.2857143 60.4285714 60.5714286 60.7142857 60.8571429
#> [427] 61.0000000 61.1428571 61.2857143 61.4285714 61.5714286 61.7142857
#> [433] 61.8571429 62.0000000 62.1428571 62.2857143 62.4285714 62.5714286
#> [439] 62.7142857 62.8571429 63.0000000 63.1428571 63.2857143 63.4285714
#> [445] 63.5714286 63.7142857 63.8571429 64.0000000 64.1428571 64.2857143
#> [451] 64.4285714 64.5714286 64.7142857 64.8571429 65.0000000 65.1428571
#> [457] 65.2857143 65.4285714 65.5714286 65.7142857 65.8571429 66.0000000
#> [463] 66.1428571 66.2857143 66.4285714 66.5714286 66.7142857 66.8571429
#> [469] 67.0000000 67.1428571 67.2857143 67.4285714 67.5714286 67.7142857
#> [475] 67.8571429 68.0000000 68.1428571 68.2857143 68.4285714 68.5714286
#> [481] 68.7142857 68.8571429 69.0000000 69.1428571 69.2857143 69.4285714
#> [487] 69.5714286 69.7142857 69.8571429 70.0000000 70.1428571 70.2857143
#> [493] 70.4285714 70.5714286 70.7142857 70.8571429 71.0000000 71.1428571
#> [499] 71.2857143 71.4285714 71.5714286 71.7142857 71.8571429 72.0000000
#> [505] 72.1428571 72.2857143 72.4285714 72.5714286 72.7142857 72.8571429
#> [511] 73.0000000 73.1428571 73.2857143 73.4285714 73.5714286 73.7142857
#> [517] 73.8571429 74.0000000 74.1428571 74.2857143 74.4285714 74.5714286
#> [523] 74.7142857 74.8571429 75.0000000 75.1428571 75.2857143 75.4285714
#> [529] 75.5714286 75.7142857 75.8571429 76.0000000 76.1428571 76.2857143
#> [535] 76.4285714 76.5714286 76.7142857 76.8571429 77.0000000 77.1428571
#> [541] 77.2857143 77.4285714 77.5714286 77.7142857 77.8571429 78.0000000
#> [547] 78.1428571 78.2857143 78.4285714 78.5714286 78.7142857 78.8571429
#> [553] 79.0000000 79.1428571 79.2857143 79.4285714 79.5714286 79.7142857
#> [559] 79.8571429 80.0000000 80.1428571 80.2857143 80.4285714 80.5714286
#> [565] 80.7142857 80.8571429 81.0000000 81.1428571 81.2857143 81.4285714
#> [571] 81.5714286 81.7142857 81.8571429 82.0000000 82.1428571 82.2857143
#> [577] 82.4285714 82.5714286 82.7142857 82.8571429 83.0000000 83.1428571
#> [583] 83.2857143 83.4285714 83.5714286 83.7142857 83.8571429 84.0000000
#> [589] 84.1428571 84.2857143 84.4285714 84.5714286 84.7142857 84.8571429
#> [595] 85.0000000 85.1428571 85.2857143 85.4285714 85.5714286 85.7142857
#> [601] 85.8571429 86.0000000 86.1428571 86.2857143 86.4285714 86.5714286
#> [607] 86.7142857 86.8571429 87.0000000 87.1428571 87.2857143 87.4285714
#> [613] 87.5714286 87.7142857 87.8571429 88.0000000 88.1428571 88.2857143
#> [619] 88.4285714 88.5714286 88.7142857 88.8571429 89.0000000 89.1428571
#> [625] 89.2857143 89.4285714 89.5714286 89.7142857 89.8571429 90.0000000
#> [631] 90.1428571 90.2857143 90.4285714 90.5714286 90.7142857 90.8571429
#> [637] 91.0000000 91.1428571 91.2857143 91.4285714 91.5714286 91.7142857
#> [643] 91.8571429 92.0000000 92.1428571 92.2857143 92.4285714 92.5714286
#> [649] 92.7142857 92.8571429 93.0000000 93.1428571 93.2857143 93.4285714
#> [655] 93.5714286 93.7142857 93.8571429 94.0000000 94.1428571 94.2857143
#> [661] 94.4285714 94.5714286 94.7142857 94.8571429 95.0000000 95.1428571
#> [667] 95.2857143 95.4285714 95.5714286 95.7142857 95.8571429 96.0000000
#> [673] 96.1428571 96.2857143 96.4285714 96.5714286 96.7142857 96.8571429
#> [679] 97.0000000 97.1428571 97.2857143 97.4285714 97.5714286 97.7142857
#> [685] 97.8571429 98.0000000 98.1428571 98.2857143 98.4285714 98.5714286
#> [691] 98.7142857 98.8571429 99.0000000 99.1428571 99.2857143 99.4285714
#> [697] 99.5714286 99.7142857 99.8571429