nnodes: Counts the number of nodes (Vertices) in a tree

Description Usage Arguments Details Value See Also Examples

View source: R/nleaves.R

Description

Counts the number of nodes in a tree (dendrogram, hclust, phylo).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
nnodes(x, ...)

## Default S3 method:
nnodes(x, ...)

## S3 method for class 'dendrogram'
nnodes(x, ...)

## S3 method for class 'hclust'
nnodes(x, ...)

## S3 method for class 'phylo'
nnodes(x, ...)

Arguments

x

tree object (dendrogram or hclust)

...

not used

Details

The idea for the name is from functions like ncol, and nrow.

The phylo method is based on turning the phylo to hclust and than to dendrogram. It may not work for complex phylo trees.

Value

The number of leaves in the tree

See Also

nrow, count_terminal_nodes, nleaves

Examples

1
2
3
4
5
hc <- hclust(dist(USArrests[1:5,]), "ave")
dend <- as.dendrogram(hc)

nnodes(dend) # 9
nnodes(hc) # 9

Example output

---------------------
Welcome to dendextend version 1.5.2
Type citation('dendextend') for how to cite the package.

Type browseVignettes(package = 'dendextend') for the package vignette.
The github page is: https://github.com/talgalili/dendextend/

Suggestions and bug-reports can be submitted at: https://github.com/talgalili/dendextend/issues
Or contact: <tal.galili@gmail.com>

	To suppress this message use:  suppressPackageStartupMessages(library(dendextend))
---------------------


Attaching package: 'dendextend'

The following object is masked from 'package:stats':

    cutree

[1] 9
[1] 9

dendextend documentation built on May 29, 2017, 3:29 p.m.

Search within the dendextend package
Search all R packages, documentation and source code