Categories &

Functions List

Function Reference: findgroups

datatypes: G = findgroups (A)
datatypes: G = findgroups (A1, …, AN)
datatypes: [G, ID] = findgroups (A)
datatypes: [G, ID1, …, IDN] = findgroups (A1, …, AN)

Find groups defined by one or more grouping variables.

G = findgroups (A) returns G, a column vector of positive integer group numbers with one element per element of the grouping variable A. The groups are the sorted unique values of A: if N groups are found, every integer between 1 and N labels a group. Elements of A that are missing (NaN, NaT, <missing>, '', or <undefined>) are labelled NaN in G. A can be a numeric, logical, string, cellstr, char, datetime, duration, calendarDuration, or categorical vector.

G = findgroups (A1, …, AN) defines groups as the sorted unique combinations of values across the grouping variables A1, …, AN, which must all have the same number of elements.

[G, ID] = findgroups (A) also returns ID, the sorted unique values of A that identify each group. With multiple grouping variables, [G, ID1, …, IDN] = findgroups (A1, …, AN) returns one identifier vector per grouping variable.

To group the variables of a table, call findgroups (T), which dispatches to the table method and returns the group identifiers as a table.

See also: splitapply, table

Source Code: findgroups