## 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"), ...)
ts
or tis
time series.x
.x
.nfrequency
is a
sub-multiple of the original frequency.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.
apply
, lapply
, tapply
,
aggregate
, and convert
.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