Main Content

Number of group elements

computes the number of elements in each group of data in a table or timetable, and returns
a table containing the groups, their counts, and the percentage (0 to 100) each count
represents. Each group is defined by a unique combination of grouping variables in
`G`

= groupcounts(`T`

,`groupvars`

)`groupvars`

. For example, ```
G =
groupcounts(T,'Gender')
```

returns a table showing the number of
`Male`

elements, the number of `Female`

elements, and
so on for any other categories in the variable `Gender`

.

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

= groupcounts(___,`Name,Value`

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

excludes the group
made from missing `categorical`

data indicated by
`<undefined>`

.

specifies additional grouping properties using one or more name-value pairs.`B`

= groupcounts(___,`Name,Value`

)

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 grouping variable of type`char`

(such as`Gender`

with elements`'Male'`

and`'Female'`

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

.

`discretize`

| `findgroups`

| `groupfilter`

| `groupsummary`

| `grouptransform`

| `rowfun`

| `splitapply`

| `varfun`