Compute Column by Column Summaries of Groups of Observations in Data Frame

DESCRIPTION:
Given a data frame and one or more grouping vectors and a summary function, return a data frame containing results of summaries of each column broken down by group.

USAGE:
aggregate.data.frame(x, by, FUN, ...)

REQUIRED ARGUMENTS:
x:
A data frame. If x is not a data frame it will be converted to one using the data.frame function.
by:
A list of grouping vectors, each as long as a column of x. The list should be named so that the result can use those names for its corresponding columns.
FUN:
A function that can be applied to any column of x that returns a single value.

OPTIONAL ARGUMENTS:
...:
Any other arguments will be passed to FUN.

VALUE:
A data frame with a column for each column in by and x. The columns arising from by will contain each unique combination of values in the grouping vectors (excluding combinations not seen in the data). The columns arising from x will contain the value of FUN applied to the partitions induced by the grouping vectors on each column of x.

DETAILS:
This is the "data.frame" method for the generic function aggregate.

NOTE:
If a x has columns of various types it may be difficult to find a summary function that works on all columns. It may be easier to use aggregate.data.frame on just certain columns of x.

SEE ALSO:
apply , by , merge , tapply .

EXAMPLES:
aggregate(state.x77, list(Region=state.region), mean)

# Gives the following output: Region Population Income Illiteracy Life.Exp Murder HS.Grad 1 Northeast 5495.111 4570.222 1.000000 71.26444 4.722222 53.96667 2 South 4208.125 4011.938 1.737500 69.70625 10.581250 44.34375 3 North Central 4803.000 4611.083 0.700000 71.76667 5.275000 54.51667 4 West 2915.308 4702.615 1.023077 71.23462 7.215385 62.00000 Frost Area 1 132.7778 18141.00 2 64.6250 54605.12 3 138.8333 62652.00 4 102.1538 134463.00

aggregate(state.x77, list(Region=state.region, Cold=state.x77[,"Frost"]>130), mean)

# Gives the following output: Region Cold Population Income Illiteracy Life.Exp Murder 1 Northeast FALSE 8802.8000 4780.400 1.1800000 71.12800 5.580000 2 South FALSE 4208.1250 4011.938 1.7375000 69.70625 10.581250 3 North Central FALSE 7233.8333 4633.333 0.7833333 70.95667 8.283333 4 West FALSE 4582.5714 4550.143 1.2571429 71.70000 6.828571 5 Northeast TRUE 1360.5000 4307.500 0.7750000 71.43500 3.650000 6 North Central TRUE 2372.1667 4588.833 0.6166667 72.57667 2.266667 7 West TRUE 970.1667 4880.500 0.7500000 70.69167 7.666667 HS.Grad Frost Area 1 52.06000 110.6000 21838.60 2 44.34375 64.6250 54605.12 3 53.36667 120.0000 56736.50 4 60.11429 51.0000 91863.71 5 56.35000 160.5000 13519.00 6 55.66667 157.6667 68567.50 7 64.20000 161.8333 184162.17