| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/nleaves.R |
| 3 |
\name{nleaves} |
| 4 |
\alias{nleaves} |
| 5 |
\alias{nleaves.default} |
| 6 |
\alias{nleaves.dendrogram} |
| 7 |
\alias{nleaves.dendlist} |
| 8 |
\alias{nleaves.hclust} |
| 9 |
\alias{nleaves.phylo} |
| 10 |
\title{Counts the number of leaves in a tree} |
| 11 |
\usage{ |
| 12 |
nleaves(x, ...) |
| 13 |
|
| 14 |
\method{nleaves}{default}(x, ...) |
| 15 |
|
| 16 |
\method{nleaves}{dendrogram}(x, method = c("members", "order"), ...) |
| 17 |
|
| 18 |
\method{nleaves}{dendlist}(x, ...) |
| 19 |
|
| 20 |
\method{nleaves}{hclust}(x, ...) |
| 21 |
|
| 22 |
\method{nleaves}{phylo}(x, ...) |
| 23 |
} |
| 24 |
\arguments{ |
| 25 |
\item{x}{tree object (dendrogram/hclust/phylo,\link{dendlist})} |
| 26 |
|
| 27 |
\item{...}{not used} |
| 28 |
|
| 29 |
\item{method}{a character scalar (default is "members"). If "order" |
| 30 |
than nleaves is based on length of \link{order.dendrogram}. |
| 31 |
If "members", than length is trusting what is written in the |
| 32 |
dendrogram's root \link{attr}. |
| 33 |
"members" is about 4 times faster than "order".} |
| 34 |
} |
| 35 |
\value{ |
| 36 |
The number of leaves in the tree |
| 37 |
} |
| 38 |
\description{ |
| 39 |
Counts the number of leaves in a tree (dendrogram or hclust). |
| 40 |
} |
| 41 |
\details{ |
| 42 |
The idea for the name is from functions like ncol, and nrow. |
| 43 |
|
| 44 |
Also, it is worth noting that the nleaves.dendrogram is based on |
| 45 |
order.dendrogram instead of labels.dendrogram since the first is |
| 46 |
MUCH faster than the later. |
| 47 |
|
| 48 |
The phylo method is based on turning the phylo to hclust and than to |
| 49 |
dendrogram. It may not work for complex phylo trees. |
| 50 |
} |
| 51 |
\examples{ |
| 52 |
hc <- hclust(dist(USArrests[1:5, ]), "ave") |
| 53 |
dend <- as.dendrogram(hc) |
| 54 |
|
| 55 |
nleaves(dend) # 5 |
| 56 |
nleaves(hc) # 5 |
| 57 |
} |
| 58 |
\seealso{ |
| 59 |
\link{nrow}, \link{count_terminal_nodes} |
| 60 |
} |