# grpstats

Summary statistics organized by group

## Syntax

## Description

returns a table with group summary statistics for the variables in the table
`tblstats`

= grpstats(`tbl`

,`groupvars`

)`tbl`

, where the function determines the groups according
to the grouping variables in `tbl`

specified by
`groupvars`

.

If all variables in `tbl`

(other than the grouping
variables) are numeric or logical, then the summary statistic is the mean of
each group for each variable in `tbl`

. Otherwise, the summary
statistic is the number of elements in each group. `tblstats`

contains a row for each observed unique value or combination of values in the
grouping variables.

specifies the summary statistic types `tblstats`

= grpstats(`tbl`

,`groupvars`

,`whichstats`

)`whichstats`

.

specifies additional options using one or more name-value arguments. For
example, `tblstats`

= grpstats(`tbl`

,`groupvars`

,`whichstats`

,`Name,Value`

)`"DataVars",[2,4]`

instructs the function to compute
summary statistics for the second and fourth variables in
`tbl`

.

returns an array with group summary statistics for the columns of the matrix
`stats`

= grpstats(`X`

,`group`

)`X`

, where the function determines the groups by the
grouping variables in `group`

.

If `X`

is a numeric or logical matrix, then the summary
statistic is the mean of each group for each column of `X`

.
Otherwise, the summary statistic is the number of elements in each group.
`stats`

contains a row for each observed unique
combination of the grouping variables.

`[`

specifies the summary statistic types `stats1,...,statsN`

] = grpstats(`X`

,`group`

,`whichstats`

)`whichstats`

and
returns an array for each summary statistic.

`[`

also specifies the significance level `stats1,...,statsN`

] = grpstats(`X`

,`group`

,`whichstats`

,"`Alpha`

",a)`a`

for confidence and
prediction intervals.

`grpstats(`

plots the group means of data in the numeric or logical matrix
`X`

,`group`

,`alpha`

)`X`

, grouped by the variables in
`group`

. The function also plots the 100×(1 –
`alpha`

)% confidence interval for each group mean. The
grouping variable values are on the horizontal plot axis.

If

`X`

is a matrix, then`grpstats`

plots the means and confidence intervals for each column of`X`

.If

`group`

is a cell array of grouping variables, then`grpstats`

plots the means and confidence intervals for the groups determined by the observed unique combinations of the grouping variables.

## Examples

## Input Arguments

## Output Arguments

## Algorithms

`grpstats`

computes summary statistic values for each observed unique value or combination of values in the grouping variables.If you specify a single grouping variable, then the output of

`grpstats`

contains a row for each observed unique value of the grouping variable.`grpstats`

sorts the groups by order of appearance (if the grouping variable is a character vector or string scalar); in ascending numeric order (if the grouping variable is numeric); or in order of by category (if the grouping variable is categorical).If you specify multiple grouping variables, then the output of

`grpstats`

contains a row for each observed unique combination of values in the grouping variables. For example, if you specify two grouping variables, each with two values, then the output has four possible combinations of grouping variable values. The function computes summary statistics only for the observed combinations that exist in the input grouping variables (not all possible combinations).`grpstats`

sorts the groups by the values of the first grouping variable, then the second grouping variable, and so on.

`grpstats`

ignores missing values in`tbl`

,`X`

, and`group`

. Missing values depend on the data type:`NaN`

for`double`

,`single`

,`duration`

, and`calendarDuration`

`NaT`

for`datetime`

`<missing>`

for`string`

`<undefined>`

for`categorical`

`' '`

for`char`

`{''}`

for`cell`

of character vectors

## Alternative Functionality

MATLAB^{®} includes the function `groupsummary`

, which also returns group summaries and is recommended when
you are working with a table. `groupsummary`

allows you to specify
whether to include groups that consist of missing values and groups with zero elements
in the output. Also, the function supports various group binning schemes and anonymous
functions that require more than one input argument for custom summary
statistics.

## Extended Capabilities

## Version History

**Introduced before R2006a**