aggregate.data.frame(x, by, FUN, ...)
x is not a data frame, it is converted to one using the
data.frame function.
x. The list elements should be named so that the result can use those names for its corresponding columns.
x and that returns a single value.
FUN.
by and
x. The columns arising from
by contain each unique combination of values in the grouping vectors (excluding combinations not seen in the data). These columns have data class
"factor". The columns arising from
x contain the value of
FUN applied to the partitions induced by the grouping vectors on each column of
x.
This is the
"data.frame" method for the generic function
aggregate.
If
x has columns of various types, it might be difficult to find a summary function that works on all columns. Instead, it may be easier to use
aggregate.data.frame on only certain columns of
x.
aggregate(fuel.frame[,1:4], list(Type=fuel.frame$Type), mean) # Produces: # Type Weight Disp. Mileage Fuel # Compact Compact 2821.000 140.40000 24.13333 4.167655 # Large Large 3676.667 279.33333 20.33333 4.967794 # Medium Medium 3195.769 175.84615 21.76923 4.601413 # Small Small 2257.692 97.30769 31.00000 3.273380 # Sporty Sporty 2798.889 164.11111 26.00000 3.957606 # Van Van 3517.143 164.42857 18.85714 5.313283