
Last chance! 50% off unlimited learning
Sale ends in
Generate a sequence of dates. Based on seq.Date
, but adds support for business day and holiday sequencing.
dateSeq()
is a generic, with
methods for character
, Date
, POSIXct
, and POSIXlt
.
dateSeq(from = NULL, to = NULL, year = NULL,
by = "days", k.by = 1, length.out = NULL,
holidays = NULL, align.by = TRUE, extend = FALSE,
range = NULL, week.align = NULL)
an alternative to supplying from
and to
, create a sequence of dates from the given year.
spacing between successive values in the sequence. Can be one of "days"
, "bizdays"
, "weeks"
, "months"
, or "years"
.
An alternative way to specify by
is with a character string that encodes the k.by
, by
, and the named holidays
, e.g "+1 bizdays@NYSEC" says to create a sequence whose elements are 1 business day apart and exclude NYSEC holidays.
non-zero integer giving the width of the interval between consecutive values in the sequence in terms of the units given in by.
the length of the sequence, before additions and exceptions are included.
character string describing the holidays to exclude from the sequence when by="bizdays"
(see holidays
).
if TRUE, adjust the sequence so that each element is on a whole number of the by * k.by
units.
if TRUE and align.by is also TRUE, instead of making the entire sequence lie between from and to, make it extend just past from and to to the next aligned values.
a two-element character or Date
vector: an alternate way to specify from
and to
.
if by
is "weeks"
, specify the weekday to align to, given as number, 0 to 6 with 0 being Sunday.
A vector of dates.
The class of the returned value is the same as the class of from
for character
, Date
, POSIXct
, and
POSIXlt
. For from
of other classes, the class of the
returned value is Date
, but this may change in the future.
# NOT RUN {
dateSeq("2008-12-20", "2009-1-10")
dateSeq("2008-12-20", "2009-1-10", by = "days", k.by = 2)
library(Holidays)
dateSeq("2008-12-20", "2009-1-10", by = "bizdays", holidays = "NYSEC")
dateSeq(from = "1960-01-01", to = "1960-01-20", by = "weeks", week.align
= 0, extend = TRUE)
dateSeq(from = "2000/01/14", length.out = 5, by = "bizdays", holidays = 'NYSEC')
# }
Run the code above in your browser using DataLab