Categories &

Functions List

Function Reference: dummyvar

statistics: D = dummyvar (group)

Create dummy variables.

D = dummyvar (group) returns a matrix D containing the dummy variables associated with the grouping variables in group. Each row in D corresponds to the same observation across all variables in group and each column in D corresponds to a separate dummy variable. D is a numeric matrix of double data type containing ones and zeros.

The grouping variable in group can be specified in one of the following options:

  • a positive integer vector representing the different group levels in the ordered range 1:max (group).
  • a positive integer matrix with each column corresponding to a separate grouping variable and the integer values representing the group levels within that grouping variable in the ordered range 1:max (group).
  • a categorical column vector, in which case the number and order of columns in D correspond to the categories returned by categories (group). Categories that are defined but not present in group produce columns of zeros. Elements of group that are <undefined> result in rows of NaN values in D.
  • a cell array with its elements containing grouping variables specified as any of the above options. Note that all grouping variables in the cell array must have the same number of observations.

See also: tabulate, grp2idx, grpstats

Source Code: dummyvar