groupsummary — Compute summary statistics by group for table or array data.
groupsummary groups table rows or array observations and computes per-group statistics. Table input returns a table; array input returns summary values and can additionally return grouping values and counts.
Syntax
G = groupsummary(T, groupvars, method, datavars)
G = groupsummary(T, groupvars, groupbins, method, datavars)
B = groupsummary(A, groupvars, method)
[B, BG, BC] = groupsummary(A, groupvars, groupbins, method)Inputs
T- Type
Any- Required
- Yes
- Description
- Input table.
groupvars- Type
Any- Required
- Yes
- Description
- Grouping variable name or names.
method- Type
Any- Required
- Yes
- Description
- Summary method name or names.
datavars- Type
Any- Required
- No
- Description
- Data variable name or names.
groupbins- Type
Any- Required
- Yes
- Description
- Grouping bin specification.
datavars- Type
Any- Required
- No
- Description
- Data variable name or names, optionally followed by name-value pairs.
A- Type
Any- Required
- Yes
- Description
- Numeric array or cell array of numeric arrays.
groupvars- Type
Any- Required
- Yes
- Description
- Grouping array or cell array of grouping arrays.
nameValuePairs- Type
Any- Required
- Variadic
- Description
- Grouping options such as IncludedEdge and IncludeEmptyGroups.
Returns
G- Type
Any- Description
- Grouped table summary.
B- Type
Any- Description
- Summary values.
BG- Type
Any- Description
- Grouping values.
BC- Type
NumericArray- Description
- Group counts.
Returned values from groupsummary depend on how many outputs the caller requests.
Errors
RunMat:table:InvalidArgument- When
- Arguments or table metadata are invalid.
- Message
table: invalid argument
RunMat:table:InvalidIndex- When
- Table indexing is invalid.
- Message
table: invalid index
RunMat:table:InvalidVariable- When
- A table variable name or value is invalid.
- Message
table: invalid variable
Table and array forms
Table forms select grouping and data variables and implement mean, sum, median, min, max, count, and numel methods.
Array forms accept numeric vectors and matrices or cell arrays of numeric arrays. Matrix columns are independent variables. [B,BG,BC] returns summary values, original-class group values when representable, and double group counts.
Integer grouping keys, integer extrema, and array/table reconstruction use typed storage. Wide integer values that cannot cross a floating-point summary boundary exactly reject instead of silently rounding.
Bins and options
One numeric grouping variable supports edge vectors and positive bin counts. IncludedEdge, IncludeMissingGroups, and a supported subset of IncludeEmptyGroups are available. Native typed-integer bin-count and zero/one controls are RunMat-only forms; scalar-double and logical controls work in MATLAB-compatible mode.
Multi-group bin specifications, time bins, additional named methods, function-handle methods, and some table selector forms are not implemented. IncludeEmptyGroups=true for categorical level expansion rejects rather than claiming to enumerate absent levels.
Execution and placement
Grouping runs on the host and is a fusion boundary. Automatic internal residency can gather before grouping; explicitly resident interactive GPU data is a mode-gated RunMat extension.
The runtime grouping keys and table schema are not statically known. Static analysis distinguishes known table input from array input but does not invent group counts, output dimensions, or a table variable schema.
Examples
Summarize an array and return groups
[B,BG,BC] = groupsummary([10;20;30],[1;1;2],'mean');Preserve wide integer groups
base = uint64(9007199254740992); [B,BG] = groupsummary([base+3;base+1;base+4],[base;base+1;base],'max');Using groupsummary with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how groupsummary changes the result.
Run a small groupsummary example, explain the result, then change one input and compare the output.
Related Table functions
Table
array2table · array2timetable · categorical · cell2table · dictionary · head · iscategorical · isordinal · istable · istimetable · ordinal · pivot · rowfilter · struct2table · table · table2array · table2cell · table2struct · table2timetable · timerange · timetable · timetable2table · uitable · vartype
Indexing
dictionary.subsasgn · dictionary.subsref · table.subsasgn · table.subsref
Source you can read
Every RunMat function's source is public. Read exactly how groupsummary is executed, line by line, in Rust.
- View the source for groupsummary in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.