getcollabels

Purpose

Returns the unique set of column labels and corresponding key values for a categorical variable.

Format

{ labels, keys } = getColLabels(X, columns)
Parameters:
  • X (NxK dataframe) – data with metadata.

  • columns (scalar or string) – Name or index of the categorical variable in X to get labels from.

Returns:
  • labels (string array) – Categorical labels assigned to variables specified by columns.

  • keys (vector) – Integer key values corresponding to categorical labels assigned to the variables in X specified by columns.

Examples

// Load data
fname = getGAUSSHome("examples/yarn.xlsx");
yarn = loadd(fname, "cat(yarn_length) + cat(amplitude) + cat(load) + cycles");

// Get column labels for yarn_length
{ labels, keys } = getColLabels(yarn, "yarn_length");

// Print results
sprintf("%10s %10s", "Key", "Labels");
sprintf("%10d %10s", keys, labels);

The code above prints the following table:

Key     Labels

  0       high
  1        low
  2        med

See also

Functions setColLabels()