groupsummary
Group summary computations
Syntax
Description
Table Data
returns the unique grouping variable combinations and the number of members in
each group for table or timetable G
= groupsummary(T
,groupvars
)T
. Groups are defined by
rows in the variables in groupvars
that have the same unique
combination of values. Each row of the output table corresponds to one group.
For example, G = groupsummary(T,"HealthStatus")
returns a
table with the count of each group in the variable
HealthStatus
.
You can use groupsummary
functionality interactively by
adding the Compute by
Group task to a live script.
For more information, see Group Summary Computation.
applies the group-wise computations specified in G
= groupsummary(T
,groupvars
,method
)method
and
appends the computation results to the output table as additional variables. For
example, G = groupsummary(T,"Location","median")
returns the
median value of every nongrouping variable in T
for each
location, in addition to the number of members in each location group.
specifies additional grouping properties using one or more name-value arguments
for any of the previous syntaxes. For example, G
= groupsummary(___,Name,Value
)G =
groupsummary(T,"Category1","IncludeMissingGroups",false)
excludes
the group made from missing data of type categorical
indicated by <undefined>
in
Category1
.
Array Data
returns the concatenated results of applying the group-wise computations in
B
= groupsummary(A
,groupvars
,method
)method
to unique groups in vector, matrix, or cell array
A
. Groups are defined by rows in the column vectors in
groupvars
that have the same unique combination of
values. Each row of the output array contains the computation results for one
group.
You can use groupsummary
functionality interactively by
adding the Compute by
Group task to a live script.
specifies additional grouping properties using one or more name-value arguments
for either of the previous syntaxes for an input array.B
= groupsummary(___,Name,Value
)
Examples
Input Arguments
Name-Value Arguments
Output Arguments
More About
Tips
When making many calls to
groupsummary
, consider converting grouping variables to typecategorical
orlogical
when possible for improved performance. For example, if you have a string array grouping variable (such asHealthStatus
with elements"Poor"
,"Fair"
,"Good"
, and"Excellent"
), you can convert it to a categorical variable using the commandcategorical(HealthStatus)
.The
groupsummary
function computes one-dimensional summary statistics. To compute grouped summaries in two dimensions, consider using thepivot
function.
Alternative Functionality
Live Editor Task
You can use groupsummary
functionality interactively by adding
the Compute by
Group task to a live script.
Extended Capabilities
Version History
Introduced in R2018aSee Also
Functions
pivot
|grouptransform
|groupfilter
|groupcounts
|summary
|findgroups
|splitapply
|discretize
|varfun
|rowfun
|convertvars
|vartype
|numunique