dateShift: Date shifting

Description Usage Arguments Value Author(s) See Also Examples

View source: R/dateShift.R

Description

Shift a date vector a number of days, bizdays, months, weeks or years. dateShift() is a generic, with methods for character, Date, POSIXct, and POSIXlt.

Usage

1
2
dateShift(x, by = "days", k.by = 1, direction = 1, holidays = NULL,
          silent = FALSE, optimize.dups=TRUE)

Arguments

x

Date vector, or a character vector that can be converted to Date by dateParse.

by

character string with the time unit of the shifts. Can be one of "days", "bizdays","weeks", "months", or "years".

k.by

positive integer with the number of by time units to shift.

direction

integer with the direction to shift. A value of 1 for the future, and -1 for the past.

holidays

character string naming the holiday series (see holidays).

silent

logical indicating whether or not to suppress warnings about arguments.

optimize.dups

If TRUE, internally optimize by not performing the same computation multiple times for duplicates. This does not change the return value.

Value

Date vector that is a time shifted version of the input dates. If shifting by "bizdays", weekends and holidays will be skipped. The class of the returned value is the same as the class of x for character, Date, POSIXct, and POSIXlt. For x of other classes, the class of the returned value is Date, but this may change in the future.

Author(s)

Lars Hansen, Tony Plate

See Also

dateAlign, dateWarp, dateMatch, dateParse, dateSeq

Examples

1
2
3
4
5
6
7
8
dateShift("2007/12/06", by = "days", k.by = 7, direction = -1)
date <- as.Date("2009/1/1") + -5:5
dateShift(date, by = "days", silent = TRUE)
library(Holidays)
dateShift(date, by = "bizdays", k.by = 5, holidays = "NYSEC")
dateShift(date, by = "weeks", k.by = 2)
dateShift(date, by = "months", k.by = "3", direction = "-1")
dateShift(date, by = "years", k.by = 1, direction = 1)

Example output

[1] "2007-11-29"
 [1] "2008-12-28" "2008-12-29" "2008-12-30" "2008-12-31" "2009-01-01"
 [6] "2009-01-02" "2009-01-03" "2009-01-04" "2009-01-05" "2009-01-06"
[11] "2009-01-07"
 [1] "2009-01-05" "2009-01-05" "2009-01-06" "2009-01-07" "2009-01-08"
 [6] "2009-01-08" "2009-01-09" "2009-01-09" "2009-01-09" "2009-01-12"
[11] "2009-01-13"
 [1] "2009-01-10" "2009-01-11" "2009-01-12" "2009-01-13" "2009-01-14"
 [6] "2009-01-15" "2009-01-16" "2009-01-17" "2009-01-18" "2009-01-19"
[11] "2009-01-20"
 [1] "2008-09-27" "2008-09-28" "2008-09-29" "2008-09-30" "2008-10-01"
 [6] "2008-10-01" "2008-10-02" "2008-10-03" "2008-10-04" "2008-10-05"
[11] "2008-10-06"
 [1] "2009-12-27" "2009-12-28" "2009-12-29" "2009-12-30" "2009-12-31"
 [6] "2010-01-01" "2010-01-02" "2010-01-03" "2010-01-04" "2010-01-05"
[11] "2010-01-06"

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