timeAlign
Alignment of Times
Description
Aligns a time vector to a time unit specified as in timeSeq.
Usage
timeAlign(x, by="days", k.by=1, direction=1, week.align=NULL,
holidays=timeDate())
Arguments
x |
a time/date object.
|
by |
one of the following character strings, giving the units to align to:
- "milliseconds"
- "seconds"
- "minutes"
- "hours"
- "days",
- "weekdays"
- "bizdays"
- "weeks"
- "months"
- "quarters"
- "years"
|
k.by |
a non-zero integer giving the number of the by units to align to.
Ignored for "weekdays", "bizdays", and "weeks".
|
direction |
either 1 or -1, to align to the next or previous time that is an
integer number of the k.by * by units.
|
week.align |
if not NULL, and by is "weeks", you can supply a character
string (or an integer, 0 to 6 with 0 being Sunday)
to specify a weekday to align to. The character string must
be sufficient to make a unique case-insensitive match to the strings
in timeDateOptions("time.day.name").
|
holidays |
dates of holidays for business day alignment.
|
Value
returns a time object 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 larger time unit
(for example, if by="days",
then align to multiples of k.by days added to the first of the
month. If by="hours", align to multiples of k.by hours since
midnight).
Notes
- for "weeks", "weekdays", and "bizdays",
k.by is assumed to be 1 and ignored.
- "weeks" without week.align is equivalent to "days".
- k.by should be a divisor of the number of
by units in the next larger time unit, or NA values
result.
See Also
Examples
x <- timeDate(c("2/11/1992 22:34", "7/8/1995 08:32"),
format="%a %02m/%02d/%Y %02H:%02M")
# move to beginning of month
timeAlign(x,"months",direction=-1)
# move to beginning of next month
timeAlign(x,"months",direction=1)
# move to next multiple of 3 hours
timeAlign(x,"hours",3)
# move to next Friday
timeAlign(x,"weeks", week.align="Friday")