dateSeq: Create a sequence of Dates

Description Usage Arguments Value Examples

View source: R/dateSeq.R

Description

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.

Usage

1
2
3
4
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)

Arguments

from

starting value of the sequence, a Date object, or number or character string recognized by dateParse.

to

ending value of the sequence, a Date object, or number or character string recognized by dateParse.

year

an alternative to supplying from and to, create a sequence of dates from the given year.

by

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.

k.by

non-zero integer giving the width of the interval between consecutive values in the sequence in terms of the units given in by.

length.out

the length of the sequence, before additions and exceptions are included.

holidays

character string describing the holidays to exclude from the sequence when by="bizdays" (see holidays).

align.by

if TRUE, adjust the sequence so that each element is on a whole number of the by * k.by units.

extend

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.

range

a two-element character or Date vector: an alternate way to specify from and to.

week.align

if by is "weeks", specify the weekday to align to, given as number, 0 to 6 with 0 being Sunday.

Value

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.

Examples

1
2
3
4
5
6
7
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')

TimeWarp documentation built on May 2, 2019, 11:11 a.m.