seq.jdate | R Documentation |
The method for seq for objects of class jdate
.
## S3 method for class 'jdate'
seq(from, to, by, length.out = NULL, along.with = NULL, ...)
from |
starting date. Required. |
to |
end date. Optional. |
by |
increment of the sequence. Optional. See ‘Details’. |
length.out |
integer, optional. Desired length of the sequence. |
along.with |
take the length from the length of this argument. |
... |
arguments passed to or from other methods. |
by
can be specified in several ways:
A number, taken to be in days.
A object of class difftime.
A character string, containing one of "day", "week", "month", "quarter" or "year". This can optionally be preceded by a (positive or negative) integer and a space, or followed by "s".
A vector of jdate
objects.
seq.Date()
The source code of seq.jdate()
is a modified version of the code used in base::seq.Date()
.
But a few behaviors of the latter are changed:
In base R, invalid dates resolve by overflowing according to the number of days that the
date is invalid by. But seq.jdate()
resolves invalid dates by rolling forward to the
first day of the next month.
If usage of to
and length.out
results in a fractional sequence between from
and to
,
base R keeps the fraction in the underlying data of the output Date
object. But since
jdate
is built upon whole numbers, the fractional part is dropped in the output.
These differences are illustrated in the examples.
base::seq.Date()
# by days
seq(jdate("1402-01-01"), jdate("1402-01-10"), 1)
# by 2 weeks
seq(jdate("1402-01-01"), jdate("1402-04-01"), "2 weeks")
# first days of years
seq(jdate("1390-01-01"), jdate("1399-01-01"), "years")
# by month
seq(jdate("1400-01-01"), by = "month", length.out = 12)
# quarters
seq(jdate("1400-01-01"), jdate("1403-01-01"), by = "quarter")
# fractional dates are allowed in `seq.Date()`, but not in `seq.jdate()`
unclass(seq(as.Date(0), as.Date(3), length.out = 3))
unclass(seq(jdate(0), jdate(2), length.out = 3))
# resloving strategy for invalid dates is different in 'seq.jdate()' compared to 'seq.Date()'
seq(as.Date("2021-01-31"), by = "months", length.out = 2)
seq(jdate("1402-06-31"), by = "6 months", length.out = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.