Learn R Programming

fame (version 1.13)

aggregate.tis: Compute Summary Statistics of Time Series Subsets

Description

Splits the data into subsets, computes summary statistics for each, and returns the result in a convenient form.

Usage

## S3 method for class 'tis':
aggregate(x, FUN = sum, \dots)
## S3 method for class 'ts':
aggregate(x, nfrequency = 1, FUN = sum, ndeltat = 1,
          ts.eps = getOption("ts.eps"), ...)

Arguments

x
a ts or tis time series.
FUN
a scalar function to compute the summary statistics which can be applied to all data subsets.
nfrequency
new number of observations per unit of time; must be a divisor of the frequency of x.
ndeltat
new fraction of the sampling period between successive observations; must be a divisor of the sampling interval of x.
ts.eps
tolerance used to decide if nfrequency is a sub-multiple of the original frequency.
...
further arguments passed to or used by methods.

Details

These are time series methods for the generic aggregate function.

aggregate.ts has been reimplemented in package:fame to insure that the resulting time series starts on a boundary of the new frequency. Suppose, for example, that x is a monthly series starting in February 1990, nfrequency is 4, and FUN is mean. The package:frb implementation will return a series whose first observation is the average of the April, May and June observations of the input series, and the first element of it's tsp will be 1990.25. The quarters end in March, June, September and December. The first two monthly observations (February and March) are ignored because they don't span a quarter.

The package:stats implementation would return a quarterly series whose first observation is the average of the February, March and April monthly observations, and it's tsp will start with 1990.083, which corresponds to quarters ending in January, April, July and October. In our experience at the Fed, this is not the expected behavior. aggregate.ts and aggregate.tis operate similarly. If x is not a time series, it is coerced to one. Then, the variables in x are split into appropriate blocks of length frequency(x) / nfrequency, and FUN is applied to each such block, with further (named) arguments in ... passed to it. The result returned is a time series with frequency nfrequency holding the aggregated values.

See Also

apply, lapply, tapply, aggregate, and convert.

Examples

Run this code
z <- tis(1:24, start = latestJanuary()) ## a monthly series
aggregate(z, nf = 4, FUN = mean)        ## quarterly average
aggregate(z, nf = 1, FUN = function(x) x[length(x)]) ## December is annual level

Run the code above in your browser using DataLab