mergelevels - Merge levels

Class

@categorical

Syntax

B = mergelevels(A,oldlevels,newlevel)
B = mergelevels(A,oldlevels)

Description

B = mergelevels(A,oldlevels,newlevel) merges two or more levels of the categorical array A into a single new level. oldlevels is a cell array of strings or a two-dimensional character matrix that specifies the levels to be merged. Any elements of A that have levels in oldlevels are assigned the new level in the corresponding elements of B. newlevel is a character string that specifies the label for the new level. For ordinal arrays, the levels of A specified by oldlevels must be consecutive, and mergelevels inserts the new level to preserve the order of the levels.

B = mergelevels(A,oldlevels) merges two or more levels of A. For nominal arrays, mergelevels uses the first label in oldlevels as the label for the new level. For ordinal arrays, mergelevels uses the label corresponding to the lowest level in oldlevels as the label for the new level.

Examples

Example 1

For nominal data:

load fisheriris
species = nominal(species);
species = mergelevels(species,...
                      {'setosa','virginica'},'parent');
species = setlabels(species,'hybrid','versicolor');
getlabels(species)
ans = 
    'hybrid'   'parent'

Example 2

For ordinal data:

A = ordinal([1 2 3 2 1],{'lo','med','hi'})
A = 
     lo      med      hi      med      lo 

A = mergelevels(A,{'lo','med'},'bad')
A = 
     bad      bad      hi      bad      bad 

See Also

addlevels, droplevels, islevel, reorderlevels, getlabels

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS