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