Description Usage Arguments Value Author(s) See Also Examples
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
.
1 2 |
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
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)
|
[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"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.