# groupcounts

Number of group elements

## Syntax

## Description

### Table Data

returns the unique grouping variable combinations for table or timetable
`G`

= groupcounts(`T`

,`groupvars`

)`T`

, the number of members in each group, and the percentage of the
data each group represents in the range [0, 100]. 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 =
groupcounts(T,"HealthStatus")
```

returns a table with the count and percentage of
each group in the variable `HealthStatus`

.

specifies to bin rows in `G`

= groupcounts(`T`

,`groupvars`

,`groupbins`

)`groupvars`

according to binning scheme
`groupbins`

prior to grouping. For example, ```
G =
groupcounts(T,"SaleDate","year")
```

returns the group counts and group
percentages for all sales in `T`

within each year according to the
grouping variable `SaleDate`

.

specifies additional grouping properties using one or more name-value arguments for any of
the previous syntaxes. For example, `G`

= groupcounts(___,`Name,Value`

)```
G =
groupcounts(T,"Category1","IncludeMissingGroups",false)
```

excludes the group
made from missing data of type `categorical`

indicated by
`<undefined>`

in `Category1`

.

### Array Data

specifies additional grouping properties using one or more name-value arguments for either
of the previous syntaxes for an input array.`B`

= groupcounts(___,`Name,Value`

)

## Examples

## Input Arguments

## Output Arguments

## Tips

When making many calls to

`groupcounts`

, consider converting grouping variables to type`categorical`

or`logical`

when possible for improved performance. For example, if you have a string array grouping variable (such as`HealthStatus`

with elements`"Poor"`

,`"Fair"`

,`"Good"`

, and`"Excellent"`

), you can convert it to a categorical variable using the command`categorical(HealthStatus)`

.

## Extended Capabilities

## Version History

**Introduced in R2019a**

## See Also

### Functions

`grouptransform`

|`groupsummary`

|`groupfilter`

|`findgroups`

|`splitapply`

|`discretize`

|`varfun`

|`rowfun`