Learn R Programming

ribiosUtils (version 1.7.7)

cutreeIntoOrderedGroups: Cut a tree into groups of ordered sizes

Description

Cut a tree into groups of ordered sizes

Usage

cutreeIntoOrderedGroups(tree, k = NULL, h = NULL, decreasing = TRUE)

Value

A named integer vector of cluster assignments, ordered by cluster size (largest first by default). If multiple values of k or h are provided, a matrix with one column per value.

Arguments

tree

a tree as produced by hclust, will be passed to cutree

k

an integer scalar or vector with the desired number of groups

h

numeric scalar or vector with heights where the tree should be cut.

decreasing

logical, should be the first group the largest?

Cut a tree, e.g. as resulting from hclust, into groups, with the groups being ordered by their size.

See Also

Examples

Run this code
hc <- hclust(dist(USArrests))
hck5 <- cutreeIntoOrderedGroups(hc, k = 5)
table(hck5)
## compare with cutree, which does not order the groups
table(cutree(hc, k=5))

hck25 <- cutreeIntoOrderedGroups(hc, k = 2:5)
apply(hck25, 2, table)

Run the code above in your browser using DataLab