Debian Codegraph @

man/reindex_dend.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/prune.R
3 \name{reindex_dend}
4 \alias{reindex_dend}
5 \title{Reindexing a pruned dendrogram}
6 \usage{
7 reindex_dend(dend)
8 }
9 \arguments{
10 \item{dend}{dendrogram object}
11 }
12 \value{
13 A \code{dendrogram} object with the leaf reindexed
14 }
15 \description{
16 \code{prune_leaf} does not update leaf indices as it prune
17 leaves. As a result, some leaves of the pruned dendrogram may have leaf
18 indeices larger than the number of leaves in the pruned dendrogram, which may
19 cause errors in downstream functions such as \code{as.hclust}.
20
21 This function re-indexes the leaves such that the leaf indices are no larger
22 than the total number of leaves.
23 }
24 \examples{
25 hc <- hclust(dist(USArrests[1:5, ]), "ave")
26 dend <- as.dendrogram(hc)
27
28 dend_pruned <- prune(dend, c("Alaska", "California"), reindex_dend = FALSE)
29
30 ## A leave have an index larger than the number of leaves:
31 unlist(dend_pruned)
32 # [1] 4 3 1
33 #'
34 dend_pruned_reindexed <- reindex_dend(dend_pruned)
35
36 ## All leaf indices are no larger than the number of leaves:
37 unlist(dend_pruned_reindexed)
38 # [1] 3 2 1
39
40 ## The dendrograms are equal:
41 all.equal(dend_pruned, dend_pruned_reindexed)
42 # TRUE
43 }