PivotTable
PivotTable[tab,f,rowcol,colcol]
constructs a table where the value at the position with keys {row,col} is given by applying the function f to the subtabulars corresponding to the rows of tab where rowcol has value row and colcol has value col.
PivotTable[tab,{key1f1,…},rowcols,colcols]
uses multiple aggregation functions fi denoted by keyi.
Details and Options
- PivotTable provides a way to summarize and reorganize data by applying an aggregation function to subtabulars specified by values of selected columns.
- PivotTable[tab,f,rowcols,colcols] produces a Tabular object in which rowcols are key columns.
- If the colcol specification is a list of several keys, the resulting table will have ExtendedKey column keys.
- For each group determined by Flatten[{rowcols,colcols}], 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"].
- PivotTable[tab,{key1f1,…},rowcols,colcols] is effectively PivotToColumns[AggregateRows[tab, {key1f1,…}, Flatten[{rowcols,colcols}]],{colcols,{key1,…}}].
- The following option can be given:
-
IncludeGroupAggregates False whether to show margins giving the aggregation for subsets of the groups
Examples
open allclose allBasic Examples (2)
Scope (2)
Applications (1)
The data contains information on kidney transplant patients—time in weeks to death or on-study time since transplant at the given age:
Show the mean survival time in years split according to gender and race:
Show group aggregate summaries:
Show the mean survival time in years split according to alive status versus gender and race:
Properties & Relations (1)
Perform a PivotTable operation with a given list of aggregation functions:
This is equivalent to using AggregateRows with the same aggregations, followed by PivotToColumns to restructure the result:
The group aggregate summaries can be obtained as follows:
Compare to the group aggregation row and columns of this result:
Text
Wolfram Research (2025), PivotTable, Wolfram Language function, https://reference.wolfram.com/language/ref/PivotTable.html.
CMS
Wolfram Language. 2025. "PivotTable." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PivotTable.html.
APA
Wolfram Language. (2025). PivotTable. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PivotTable.html