
The function recursively finds all leaves that are descendants of a
node in an hclust
tree.
find.leaves(ind, merge)
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.
Index of the tree node. For an hclust
tree
of p
leaves, -j
denotes the j
th leaf and k
denotes the interior node formed at the k
th merging in constructing
the tree. The range of ind
is
{-1, ..., -p, 1,..., p-1} where p-1
is the number of interior nodes.
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.
if (FALSE) {
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)
}
Run the code above in your browser using DataLab