dateShift {TimeWarp} | R Documentation |
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
.
dateShift(x, by = "days", k.by = 1, direction = 1, holidays = NULL, silent = FALSE, optimize.dups=TRUE)
x |
|
by |
character string with the time unit of the shifts.
Can be one of |
k.by |
positive integer with the number of |
direction |
integer with the direction to shift. A value of |
holidays |
character string naming the holiday series (see |
silent |
logical indicating whether or not to suppress warnings about arguments. |
optimize.dups |
If |
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.
Lars Hansen, Tony Plate
dateAlign
,
dateWarp
,
dateMatch
,
dateParse
,
dateSeq
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)