Decrease Periodicity of Time Series by Aggregation

DESCRIPTION:

Returns a shorter time series with observations that are the result of FUN applied to a partition of the original time series.

USAGE:

aggregate(x, nfrequency=1, FUN=sum, ndeltat=1, ts.eps = .Options$ts.eps, ..., fun)

REQUIRED ARGUMENTS:

x
a univariate or multivariate regular time series. Calendar time series will be coerced to regular. Missing values are allowed if FUN accepts them.

OPTIONAL ARGUMENTS:

nfrequency
desired ("new") frequency for aggregated time series; must be a divisor of the frequency of x.
FUN
function to be used in performing aggregation. Most commonly, FUN is either mean, to give the mean level for rate-like series, or FUN is sum in order to compute totals.
ndeltat
desired ("new") interval between observations; must be a divisor of the sampling interval deltat(x). The resulting series has frequency 1/ndeltat. If nfrequency is given, this is ignored.
ts.eps
This overrides the global options("ts.eps"). Frequencies are considered equal if they differ in absolute value by less than ts.eps.
...
Any unrecognized arguments will passed to FUN.
fun
Obsolete name for FUN. Please do not use this.

VALUE:

new time series with frequency nfrequency. Each group of frequency(x)/nfrequency observations is given to FUN to create the aggregated value. (Incomplete cycles are ignored.)

DETAILS:

These are the "rts" and "cts" methods for the generic function aggregate .

NOTE:

The third argument, FUN, used to be called lowercase fun, which did not match the name of this argument in other methods for aggregate. We have changed the name to FUN but fun is still accepted. However, abbreviations of fun are not recognized and will be passed to FUN as part of the ... list.

SEE ALSO:

, , , .

EXAMPLES:

aggregate(co2, 1, mean)  # yearly co2 level 
aggregate(ship, 4, sum)  # quarterly manufacturing shipments 
aggregate(ship, ndeltat=.25)  # same as above 
aggregate(lynx, nfrequency=frequency(lynx)/3, FUN=mean) # aggregate lynx every 3 observations