CFfactor {CFtime}R Documentation

Create a factor from the offsets in an CFtime instance

Description

With this function a factor can be generated for the time series, or a part thereof, contained in the CFtime instance. This is specifically interesting for creating factors from the date part of the time series that aggregate the time series into longer time periods (such as month) that can then be used to process daily CF data sets using, for instance, tapply().

Usage

CFfactor(cf, period = "month", epoch = NULL)

Arguments

cf

CFtime. An atomic instance of the CFtime class whose offsets will be used to construct the factor.

period

character. An atomic character string with one of the values "year", "season", "month" (the default), "dekad" or "day".

epoch

numeric or list, optional. Vector of years for which to construct the factor, or a list whose elements are each a vector of years. If epoch is not specified, the factor will use the entire time series for the factor.

Details

The factor will respect the calendar of the datum that the time series is built on. For periods longer than a day this will result in a factor where the calendar is no longer relevant (because calendars impacts days, not dekads, months or seasons).

The factor will be generated in the order of the offsets of the CFtime instance. While typical CF-compliant data sources use ordered time series there is, however, no guarantee that the factor is ordered as multiple CFtime objects may have been merged out of order.

If the epoch parameter is specified, either as a vector of years to include in the factor, or as a list of such vectors, the factor will only consider those values in the time series that fall within the list of years, inclusive of boundary values. Other values in the factor will be set to NA. The years need not be contiguous, within a single vector or among the list items, or in order.

The following periods are supported by this function:

It is not possible to create a factor for a period that is shorter than the temporal resolution of the source data set from which the cf argument derives. As an example, if the source data set has monthly data, a dekad or day factor cannot be created.

Creating factors for other periods is not supported by this function. Factors based on the timestamp information and not dependent on the calendar can trivially be constructed from the output of the CFtimestamp() function.

Value

If epoch is a single vector or not specified, a factor with a length equal to the number of offsets in cf. If epoch is a list, a list with the same number of elements and names as epoch, each containing a factor. Elements in the factor will be set to NA for time series values outside of the range of specified years.

Examples

cf <- CFtime("days since 1949-12-01", "360_day", 19830:54029)

# Create a dekad factor for the whole time series
f <- CFfactor(cf, "dekad")

# Create three monthly factors for early, mid and late 21st century epochs
ep <- CFfactor(cf, epoch = list(early = 2021:2040, mid = 2041:2060, late = 2061:2080))

[Package CFtime version 1.3.0 Index]