find.leaves {rare}R Documentation

Find all descendant leaves of a node in an hclust tree

Description

The function recursively finds all leaves that are descendants of a node in an hclust tree.

Usage

find.leaves(ind, merge)

Arguments

ind

Index of the tree node. For an hclust tree of p leaves, -j denotes the jth leaf and k denotes the interior node formed at the kth merging in constructing the tree. The range of ind is {-1, ..., -p, 1,..., p-1} where p-1 is the number of interior nodes.

merge

A (p-1)-by-2 matrix that encodes the order of mergings in constructing the tree. merge uses the same notation for nodes and mergings in an hclust object. See hclust for details.

Value

Returns a sequence of indices for descendant leaves in the leaf set {1, ..., p}. Unlike the notation used in ind, we use positive integers to denote leaves here.

Examples

## Not run: 
hc <- hclust(dist(USArrests), "ave")
# Descendant leaves of the 10th leaf (should be iteself)
find.leaves(-10, hc$merge)

# Descendant leaves of the 10th interior node
find.leaves(10, hc$merge)

# Descendant leaves of the root (should be all leaves)
ind_root <- nrow(hc$merge)
all.equal(find.leaves(ind_root, hc$merge), hc$order)

## End(Not run)


[Package rare version 0.1.1 Index]