Description Usage Arguments Details Value Author(s) See Also Examples
Perform multiple shifts and alignments on Date
vectors.
dateWarp()
is a generic, with
methods for character
, factor
, Date
, POSIXct
, and POSIXlt
.
1 2 3 4 |
date |
a |
spec |
a specification of shifts and alignment tranformations. See ‘Details’. |
holidays |
a character string naming the holiday series (see |
by |
how to warp. Can be one of |
direction |
which direction to warp. a numeric value of 1 for the future, and -1 for the past (be careful about using variables for this value, for if it's value is negative and you place a minus sign in front of the variable, you'll go back to the future). |
duplicates.keep |
logical indicating whether or not to keep duplicate dates. |
... |
arguments to pass to |
where |
character string. can be |
empty.ok |
is it okay for the |
duplicates.ok |
logical indicating whether or not to keep duplicate dates. |
optimize.dups |
If |
spec
specify tranformations in several ways:
integer vector by which to shift the current Date object. The
units of the shift are specified by the by
argument.
If the shift contains more than one element, this will
transform a single Date object into a multiple-element Date
object. It is an error to apply a multiple-element shift to
a multiple element Date object.
character data of the form "+3 bizdays@NYSEC", "+3 bizdays", or "+3". 'by' and 'holidays' specifications are extracted from the string as appropriate, and override any previously specified or given in arguments.
a named list of elements. The elements can be lists or vectors. The names on the elements specify instructions:
the actual value of the list element is ignored. The action is to remove duplicates from the results, i.e., make the dates unique.
the value of the list element is a Date
or a character that can
be converted to a Date
with
dateParse
. The dates will be clipped to be no
later than the specified Date
.
the value of the list element is a Date
or a character that can
be converted to a Date
with
dateParse
. The dates will be clipped to be no earlier
than the specified Date
.
the spec
list element is a list that will be used as arguments to a call
of dateShift
. If any are not specified in the list,
the values of the by
, holidays
, and direction
arguments given to
dateWarp()
are passed to dateShift
.
the spec
list element is a list that will be used as arguments to a call
of dateAlign
. If any are not specified in the list,
the values of the by
, holidays
, and direction
arguments given to
dateWarp()
are passed to dateShift
.
If not all arguments are not provided, the dateWarp arguments will be used instead.
A date vector that is a transformed version of the input
dates. Multiple shift or alignment transformations can be specified. If
more that one is given, each vill be applied in turn to the result of
the previous one.
The class of the returned value is the same as the class of date
for character
, Date
, POSIXct
, and
POSIXlt
. For date
of other classes, the class of the
returned value is Date
, but this may change in the future.
Lars Hansen, Tony Plate
dateAlign
,
dateShift
,
dateMatch
,
dateParse
,
and dateSeq
The Holidays
package contains holidays data, which is
registered with the TimeWarp
package when the Holidays
package is loaded.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | library(Holidays)
dates <- dateSeq("2001/12/20", by = 'bizdays', len = 9, holidays = "NYSEC")
dateWarp(dates, -1:1, by = "bizdays", holidays = "NYSEC", duplicates.keep = FALSE)
dateWarp(dates, "+1 bizdays@NYSEC")
dateWarp(dates, list(0:6), by = "bizdays@NYSEC")
dateWarp(dates, list(-1:1, unique = TRUE), by = "bizdays")
dateWarp(dates, list(latest = "2001/12/25"))
x <- dateSeq("2001/01/01", len = 4, by = "weeks")
dateWarp(dates, list(align = list(to = x, how = "after")))
dateWarp(dates, list(shift = list(by = "bizdays", k.by = 2, direction = 1, holidays = "NYSEC"),
shift = 2),
by = "days", direction = -1,
holidays = "NONE")
dateWarp(dates, hol = "NYSEC",
list(shift = list(k.by = 1, by = "months"),
shift=list(k.by = -1, by = "bizdays")))
dateWarp(dates, list(align = list(by = "bizdays"),
shift = list(by = "months", k.by = 2), holidays = "JPNEX"))
# Options expirations dates in 2008
(d1 <- dateSeq('2008-01-01', len=12, by='months'))
(d2 <- dateAlign(d1, by='months', dir=-1))
(d3 <- dateAlign(d2, by='weeks', week.align=5))
(d4 <- dateWarp(d3, 14, by='days'))
(d5 <- dateAlign(d4, by='bizdays@NYSEC', dir=-1))
# Version that uses a list 'spec' to dateWarp
dateWarp(d1, list(align=list(by='months', dir=-1),
align=list(by='weeks', week.align=5),
shift=list(by='days', 14),
align=list(by='bizdays@NYSEC', dir=-1)))
# In 2008 the March options expiration is a Thursday because Friday was a holiday
dateDow(d5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.