Grouping and Aggregation

A grouping is a collection of keys and sets of indexes into a dataset. Each element of the grouping corresponds to a subset (i.e. a group of observations) of a dataset. Groups may overlap. Moving windows and partitions are examples of groupings.

A grouping is most commonly used in combination with one or more aggregators. An aggregator is a function that reduces one or more vectors to a single value, like the sum or the mean of the elements or the correlation between two vectors. Using an aggregator in combination with a grouping on a data frame, matrix or vector results in a new data frame, matrix or vector with the aggregator applied to each group. The aggregator's index becomes the (row) index of the resulting collection. Aggregators can also be used without groupings to reduce an entire data frame, matrix or vector to a single vector or value.

In this section: