Sequences of Dates

DESCRIPTION:

Generate a vector of evenly spaced dates.

USAGE:

seq.dates(from, to, by = "days", length.out, k.by = 1) 

OPTIONAL ARGUMENTS:

from
starting date. It can be a dates object, an integer representing a Julian date, or a character string of the form "mm/dd/yy", for example "05/23/91".
to
ending date, like from. One of to or from or both needs to be specified.
by
spacing between successive values in the sequence. This can be a numeric value or a character string. If a character, it must be one of the valid strings "days", "weekdays", "weeks", "months", "quarters" or "years" giving the desired time units of the intervals between dates. Default is one day.
length.out
number of elements in the resulting sequence.
k.by
positive integer representing the width of the interval between consecutive dates in terms of the units given as the by argument. This is ignored if by is numeric or by="weekdays".

VALUE:

a sequence with the dates between from and to separated by k.by time units as defined by the argument by. The origin of the sequence will be the same as origin(from) or origin(to).

For by="weekdays", all the weekdays between from and to are generated.

DETAILS:

At least one of from or to is required plus length.out, the desired length of the resulting sequence; or both from and to in which case length.out gets ignored if supplied.

For by="weekdays", if given from (or to) is a weekend, the next Monday (or the last Friday) is used as the start (or end).

SEE ALSO:

, .

EXAMPLES:

seq.dates("01/01/92", "12/31/92", by="months") 
# Produces:
# [1] 01/01/92 02/01/92 03/01/92 04/01/92 05/01/92 06/01/92 
# [7] 07/01/92 08/01/92 09/01/92 10/01/92 11/01/92 12/01/92 

quarters1 <- seq.dates("01/01/92", "12/31/92", by="quarters") 
quarters2 <- seq.dates("01/01/92", "12/31/92",by="months",k=3) 
all(quarters1 == quarters2) 

end.of.the.month <- seq.dates("02/29/92", by="months", length=15) 
end.of.the.month 
# Produces:
#  [1] 02/29/92 03/31/92 04/30/92 05/31/92 06/30/92 07/31/92 
#  [7] 08/31/92 09/30/92 10/31/92 11/30/92 12/31/92 01/31/93 
# [13] 02/28/93 03/31/93 04/30/93