| seq.mixtime::mixtime | R Documentation |
Create regular sequences of time values. This method handles both linear time sequences (dates, date-times) and cyclical time sequences (day of week, month of year).
## S3 method for class ''mixtime::mixtime''
seq(...)
## S3 method for class ''mixtime::mt_time''
seq(
from,
to,
by,
length.out = NULL,
along.with = NULL,
on_invalid = getOption("mixtime.on_invalid", "clamp"),
...
)
... |
Additional arguments passed to the underlying sequence method. |
from |
Starting value of the sequence. |
to |
End value of the sequence (if provided). |
by |
Increment of the sequence. Can be:
|
length.out |
Desired length of the sequence (alternative to |
along.with |
Take the length from this argument (alternative to |
on_invalid |
How to handle time points that don't exist, either
because they overflow the cycle when using a
This is relevant when the starting time point has an offset that doesn't
exist in all cycles. For example, starting on day 31 with If neither |
For linear time types (Date, POSIXct, yearmonth, etc.), sequences progress
forward or backward in time. Located cyclical time (e.g.
month_of_year(yearmonth("2024-11"))) progresses through time too, so its
positions wrap around the cycle.
Underspecified cyclical time (e.g. month_of_year(11), see
mt_cyclical_free-arithmetic) follows the rules of x + by: positions in
cycles of a fixed length wrap around (a length.out sequence of months
continues from December to January), while cycles of variable length (e.g.
day_of_month()) can't be sequenced until located with time_compose().
Between from and to, the sequence runs linearly within one cycle, so
seq(month_of_year(11), month_of_year(2)) counts down from November to
February.
Each time point is from (or to, if from is missing) shifted by a whole
number of by steps, matching from + duration(k, by). For time-zone-aware times, steps of a day or
longer keep the local clock time, while shorter steps (e.g. hours) are real
time across daylight saving changes.
A mixtime vector containing the sequence.
# Linear time sequences with integer by
seq(yearmonth("2020 Jan"), yearmonth("2020 Dec"))
seq(yearquarter("2020 Q1"), length.out = 5, by = 3)
# Linear time sequences with string intervals
seq(date("2020-01-01"), date("2020-12-31"), by = "1 month")
seq(yearmonth("2020 Jan"), yearmonth("2025 Jan"), by = "1 year")
seq(date("2020-01-01"), length.out = 10, by = "2 weeks")
# Linear time sequences incrementing by time granules
seq(yearmonth("2020 Jan"), yearmonth(("2020 Dec")), by = cal_gregorian$month(2L))
seq(date("2020-01-01"), length.out = 5, by = cal_gregorian$year(1L))
seq(date("2020-01-01"), date("2020-01-31"), by = cal_gregorian$day(7L))
# Handling invalid dates with on_invalid
seq(date("2020-01-31"), length.out = 3, by = "1 month") # warns, uses clamp
seq(date("2020-01-31"), length.out = 3, by = "1 month", on_invalid = "clamp")
seq(date("2020-01-31"), length.out = 3, by = "1 month", on_invalid = "next")
seq(date("2020-01-31"), length.out = 3, by = "1 month", on_invalid = "overflow")
# Cyclical time sequences
seq(month_of_year(1L), month_of_year(12L))
seq(day_of_week(1L), day_of_week(7L), by = 1)
seq(month_of_year(11L), by = "1 month", length.out = 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.