seq.mondate: Mondate Sequence Generation

View source: R/seq.mondate.r

seq.mondateR Documentation

Mondate Sequence Generation

Description

Generate regular mondate sequences.

Usage

## S3 method for class 'mondate'
seq(from, to, by, ..., right = TRUE)

Arguments

from

coercible to a mondate. May be "missing".

to

coercible to a mondate. May be "missing".

by

increment of the sequence. If numeric, a sequence is generated using the underlying numeric value(s) of the coerced argument(s) and converted to a mondate object (see seq). If "days" or "weeks", a sequence is generated using "Date" objects coerced from the mondate-coerced arguments (see seq.Date). If "months", "years", or "quarters", by is converted to 1, 12, or 3, respectively, and the numeric case continues. Furthermore, the characters can optionally be preceded by a (positive or negative) integer and a space, and the singular form may also be used.

...

optional arguments passed to seq or, if by "day" or "week", seq.Date

right

in the case when by specifies units of multiples of months ("months", "years", or "quarters") should increments be considered as attaching to the end of the day (the mondate default). If FALSE, the increment attaches to the beginning of the day (see "Examples")

Details

For more details about sequence generation, see seq.

If from and to are both provided, the displayFormat and timeunits properties are taken from from, without a warning if from's properties differ from to's.

Value

A mondate vector with slots (including displayFormat, timeunits, formatFUN) from argument from, if provided, otherwise from argument to.

Author(s)

Dan Murphy

See Also

seq, seq.Date and seqmondate

Examples

x <- mondate.ymd(2010, 1)   # January 31, 2014
y <- mondate.ymd(2010, 12)  # December 31, 2014
seq(from = x, to = y, by = 1)  # all month-ends in 2014
# 8 quarter-ends beginning 1st quarter 2009; US displayFormat
seq(mondate("3/31/2009"), by = 3, length.out = 8) 
# 8 quarter-ends ending year-end 2009; R's date format
seq(to = mondate("2009-12-31"), by = 3, length.out = 8)
#
# Use of RIGHT = FALSE in seq.mondate is depracated. 
# Instead, to generate sequences of 
#   Dates corresponding to the first days of the months
# use the seq.Date method.
seqmondate(as.Date("2014-01-01"), by = "months", length = 12)
# To generate the last day of a sequence of months, 
#   use the default right = TRUE:
(m <- seq.mondate(as.Date("2014-01-31"), by = "months", length = 12))
# Coerce back to Date if necessary:
as.Date(m) 
# Note how the Date method yields a different sequence, not corresponding to
#   the last day of the month. 
seq(as.Date("2014-01-31"), by = "months", length = 12)


chiefmurph/mondate documentation built on Aug. 29, 2022, 4:13 p.m.