cut,CFtime-method {CFtime}R Documentation

Create a factor for a CFtime instance

Description

Method for base::cut() applied to CFtime objects.

Usage

## S4 method for signature 'CFtime'
cut(x, breaks, ...)

Arguments

x

An instance of CFtime.

breaks

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.

Details

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. The earliest timestamp cannot be earlier than the origin of the datum of x.

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.

Value

A factor with levels according to the breaks argument, with attributes 'period', 'epoch' 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 'epoch' is always -1.

See Also

CFfactor() produces a factor for several fixed periods, including for epochs.

Examples

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)

[Package CFtime version 1.4.0 Index]