AggregateRows
AggregateRows[tab,{key1f1,…}]
computes different aggregation functions fi[tab] and assigns them to different keys keyi.
AggregateRows[tab,fspec,gspec]
forms groups by the distinct values given by gspec and then aggregates them using fspec.
AggregateRows[fspec]
represents an operator form for the two-argument version of AggregateRows.
AggregateRows[fspec,gspec]
represents an operator form for the three-argument version of AggregateRows.
Details
- AggregateRows is also known as tabular reduce.
- AggregateRows is typically used to summarize the data in groups of rows.
- Possible forms of tab include:
-
Tabular[…] type-consistent tabular data Dataset[…] general hierarchical data {assoc1,assoc2,…} list of associations with common keys - The application of AggregateRows does not change the form of tab.
- For each group, there is a subtabular stab corresponding to a subset of rows of tab. The aggregation functions fi are applied to the association of columns given by FromTabular[stab,"Columns"].
- Possible forms of grouping specification gspec include:
-
key groups by distinct values associated with key newkeyg groups by distinct values of g[rowi], adding them as newkey {spec1,…} groups by distinct values of all the speci together
Examples
open allclose allBasic Examples (2)
Take a Tabular object:
Aggregate all rows by computing the total of the values of column "col2":
Aggregate rows by first grouping those with common value of column "col1" and then totaling:
Aggregate a list of associations by computing a function of the values of key "a":
Aggregate associations by first grouping those with common value of key "b":
Scope (8)
Input Data (3)
Aggregation Functions (2)
Take a Tabular object:
The aggregation function f receives an association with all columns, each one a list of values:
Use a pure function with named Slot notation to extract individual columns in the aggregation:
Alternatively, use Part notation:
Aggregate a Tabular object with a list of aggregation functions:
Grouping Specifications (3)
Aggregate rows by first grouping those with common value of column "col1" and then averaging:
Aggregate rows by grouping those with common value determined by the function g and then averaging:
Use a specific grouping function:
Take a Tabular object:
Aggregate rows by first grouping those with common values of pairs of columns "b" and "c":
Applications (4)
Take a Tabular object with measurements of soil pH at three depth levels of 0, 30 and 80 meters:
Take measurements of various species of iris flower:
Compute the mean of the second column:
Compute the median of the "PetalLength" column:
Compute number of observations for each species:
Compute the mean of "SepalLength" for each species variety:
Old Faithful geyser data containing eruption times and next eruption waiting times in minutes:
Compute correlation between the columns:
Visualize the waiting time vs. duration:
Compute mean of the durations depending on the waiting time:
Convert into the normal form of the Tabular object:
Take a table of data about penguins in the Palmer Archipelago:
Possible Issues (1)
Using AggregateRows without grouping input may reduce a Tabular object too much:
Text
Wolfram Research (2025), AggregateRows, Wolfram Language function, https://reference.wolfram.com/language/ref/AggregateRows.html.
CMS
Wolfram Language. 2025. "AggregateRows." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/AggregateRows.html.
APA
Wolfram Language. (2025). AggregateRows. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AggregateRows.html