CFTime
instanceMethod for base::cut()
applied to CFTime objects.
# S3 method for CFTime
cut(x, breaks, ...)
A factor with levels according to the breaks
argument, with
attributes 'period', 'era' and 'CFTime'. When breaks
is a factor
period, attribute 'period' has that value, otherwise it is '"day"'. When
breaks
is a character vector of timestamps, attribute 'CFTime' holds an
instance of CFTime
that has the same definition as x
, but with (ordered)
offsets generated from the breaks
. Attribute 'era' is always -1.
An instance of CFTime
.
A character string of a factor period (see CFfactor()
for a
description), or a character vector of timestamps that conform to the
calendar of x
, with a length of at least 2. Timestamps must be given in
ISO8601 format, e.g. "2024-04-10 21:31:43".
Ignored.
When breaks
is one of "year", "season", "quarter", "month", "dekad", "day"
a factor is generated like by CFfactor()
.
When breaks
is a vector of character timestamps a factor is produced with a
level for every interval between timestamps. The last timestamp, therefore,
is only used to close the interval started by the pen-ultimate timestamp -
use a distant timestamp (e.g. range(x)[2]
) to ensure that all offsets to
the end of the CFTime
time series are included, if so desired. The last
timestamp will become the upper bound in the CFTime
instance that is
returned as an attribute to this function so a sensible value for the last
timestamp is advisable.
This method works similar to base::cut.POSIXt()
but there are some
differences in the arguments: for breaks
the set of options is different
and no preceding integer is allowed, labels
are always assigned using
values of breaks
, and the interval is always left-closed.
CFfactor()
produces a factor for several fixed periods, including
for eras.
x <- CFtime("days since 2021-01-01", "365_day", 0:729)
breaks <- c("2022-02-01", "2021-12-01", "2023-01-01")
cut(x, breaks)
Run the code above in your browser using DataLab