Skip to contents

Given a weighted rooted tree tree, PathLengths() returns the distance from each vertex to each of its descendant vertices.

Usage

PathLengths(tree, fullMatrix = FALSE)

Arguments

tree

Original tree of class phylo, in Preorder.

fullMatrix

Logical specifying return format; see "value" section`.

Value

If fullMatrix = TRUE, PathLengths() returns a square matrix in which entry [i, j] denotes the distance from internal node i to the descendant vertex j. Vertex pairs without a continuous directed path are denoted NA. If fullMatrix = FALSE, PathLengths() returns a data.frame with three columns: start lists the deepest node in each path (i.e. that closest to the root); end lists the shallowest node (i.e. that closest to a leaf); length lists the total length of that path.

See also

Examples

tree <- rtree(6)
plot(tree)
add.scale.bar()
nodelabels()
tiplabels()

PathLengths(tree)
#>    start end    length
#> 1      7   1 1.0503595
#> 2      8   1 0.2675082
#> 3      7   2 1.5182935
#> 4      8   2 0.7354421
#> 5      9   2 0.5167968
#> 6      7   3 1.2704472
#> 7      8   3 0.4875959
#> 8      9   3 0.2689506
#> 9      7   4 1.2625274
#> 10    10   4 1.0813591
#> 11    11   4 0.5627829
#> 12     7   5 0.8289013
#> 13    10   5 0.6477330
#> 14    11   5 0.1291569
#> 15     7   6 0.4375359
#> 16    10   6 0.2563676
#> 17     7   8 0.7828513
#> 18     7   9 1.0014966
#> 19     8   9 0.2186453
#> 20     7  10 0.1811683
#> 21     7  11 0.6997445
#> 22    10  11 0.5185761