Learn R Programming

accumulate (version 1.0.0)

csh_from_digits: Derive collapsing scheme from a hierarchical classification

Description

Derive a collapsing scheme where group labels collapse to their parents in the hierarchy.

Usage

csh_from_digits(x, levels = max(nchar(x)) - 1)

Value

A data frame where each consecitive pair of columns represents one collapsing step induced by the hierarchical classification encoded by the digits in x.

Arguments

x

[character|integer] labels in a hierarchical classification (lowest level)

levels

[integer >=0] how many collapsing levels to include. Zero means only include the original labels.

Examples

Run this code
# balanced hierarchical classification
csh_from_digits(c("111","112","121","122","123"))
csh_from_digits(c("111","112","121","122","123"),levels=1)

# unbalanced hierarchical classification
csh_from_digits(c("111","112","121","122","1221","1222"))
csh_from_digits(c("111","112","121","122","1221","1222"),levels=2)

Run the code above in your browser using DataLab