aggregate.tis {tis} | R Documentation |
Splits the data into subsets, computes summary statistics for each, and returns the result in a convenient form.
## S3 method for class 'tis' aggregate(x, FUN = sum, ...) ## S3 method for class 'ts' aggregate(x, nfrequency = 1, FUN = sum, ndeltat = 1, ts.eps = getOption("ts.eps"), ...)
x |
a |
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 |
ndeltat |
new fraction of the sampling period between
successive observations; must be a divisor of the sampling
interval of |
ts.eps |
tolerance used to decide if |
... |
further arguments passed to or used by methods. |
These are time series methods for the generic aggregate
function.
aggregate.ts
has been reimplemented in package:tis
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:tis
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