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 an S Version 3 generic (see Methods); method functions can be written to handle specific S Version 3 classes of data. Classes which already have methods for this function include:
cts, data.frame, rts, series.

USAGE:

aggregate(x, ...) 
aggregate.default(x, ...) 

REQUIRED ARGUMENTS:

x
a time series, data frame, or bdFrame. 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, data frame, or bdFrame 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:

, , , , , .

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) 
# Produces:
#                Region   Income Illiteracy Life.Exp 
#  Northeast  Northeast 4570.222   1.000000 71.26444
#      South      South 4011.938   1.737500 69.70625
# NorthCentr NorthCentr 4611.083   0.700000 71.76667
#       West       West 4702.615   1.023077 71.23462