Compute Summary Statistics of Subsets of Data

DESCRIPTION:
Splits up data by time period or other factors and computes summary for each subset.

This function is generic (see Methods); method functions can be written to handle specific classes of data. Classes which already have methods for this function include: cts, data.frame, rts.


USAGE:
aggregate(x, ...)
aggregate.default(x, ...)

REQUIRED ARGUMENTS:
x:
a time series or data frame. Currently, anything that is not a time series is converted to a data frame and old style time series (with a tsp attribute) are converted to class rts.

OPTIONAL ARGUMENTS:
...:
arguments to pass to the specific method used. See aggregate.data.frame, aggregate.rts, and aggregate.cts for acceptable arguments.

VALUE:
a time series or data frame containing the summary statistics.

DETAILS:
Each method accepts a function for computing the summary statistic. This function should always return a scalar.

Each method accepts different arguments, see aggregate.data.frame, aggregate.rts, or aggregate.cts for details.


SEE ALSO:
aggregate.data.frame , aggregate.cts , aggregate.rts , by , tapply .

EXAMPLES:
# compute 50 year averages of sunspot numbers
aggregate(sunspots, ndeltat = 50, fun = mean)

# gives the following results: [1] 53.96067 39.95750 45.09283 47.93400 start deltat frequency 1750 50 0.02

# compute regional averages of demographic data aggregate(state.x77[,2:4], list(Region = state.region), FUN = mean)

Region Income Illiteracy Life.Exp 1 Northeast 4570.222 1.000000 71.26444 2 South 4011.938 1.737500 69.70625 3 North Central 4611.083 0.700000 71.76667 4 West 4702.615 1.023077 71.23462