Description Usage Arguments Value Note Author(s) See Also Examples
Align a date vector the a day, bizday, month, week or year boundary.
dateAlign()
is a generic, with
methods for character
, Date
, POSIXct
, and POSIXlt
.
1 2 3 
x 

by 
character string with the time unit of the time period.
Can be one of 
k.by 
positive integer giving the number of the 
direction 
integer with either 1 or 1, to align to the previous or next time
that is an integer number of the 
week.align 
if not NULL, and 
holidays 
character string naming the holiday series (see

silent 
logical indicating whether or not to suppress warnings about arguments. 
optimize.dups 
If 
Date vector whose elements are moved up or down (according to
direction
) so that they lie on integer multiples of
k.by
* by
units of time starting from the beginning of
the next bigger time unit (e.g. if
by = "days"
, then align to multiples of k.by
days
added to the first of the month. Note that for "weeks"
,
and "bizdays"
, k.by
is assumed to be 1 and ignored;
"weeks"
without week.align
is equivalent
to "days". Also note that k.by
should be a divisor of the
number of by
units in the next larger time unit,
or NA values will result.
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.
Alignment of dates can be thought of as a partition on date sequences where an input date is aligned to the first date in a partition, if it is not already aligned. The direction of alignment determines which partition to use for the alignment. If the direction is 1 then alignment happens in the partition which the date falls in. If +1 then alignment happens in the partition just after the partition in which the dates falls.
Lars Hansen, Tony Plate
dateShift
,
dateWarp
,
dateMatch
,
dateParse
,
dateSeq
1 2 3 4 5 6 7 8 9 10  dateAlign("2007/12/06", by = "days", k.by = 4, direction = 1)
date < as.Date("2009/1/1") + 5:5
dateAlign(date, by = "days", silent = FALSE)
dateAlign(date, by = "days", k.by = 3, direction = 1)
dateAlign(date, by = "bizdays", k.by = 1, direction = 1)
library(Holidays)
dateAlign(date, by = "bizdays", k.by = 1, direction = 1, holidays =
"NYSEC")
dateAlign(date, by = "months", k.by = 2, direction = 1)
dateAlign(date, by = "years", k.by = 3, direction = 1)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.