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

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

Other tree properties: ConsensusWithout(), NSplits(), NTip(), SplitsInBinaryTree(), TipLabels(), TreeIsRooted()

Author

Martin R. Smith (martin.smith@durham.ac.uk)

Examples

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

PathLengths(tree)
#>    start end     length
#> 1      7   1 0.44186817
#> 2      8   1 0.29856379
#> 3      9   1 0.05893438
#> 4      7   2 1.02522205
#> 5      8   2 0.88191767
#> 6      9   2 0.64228826
#> 7      7   3 1.79848827
#> 8      8   3 1.65518389
#> 9     10   3 0.77891468
#> 10     7   4 1.81688242
#> 11     8   4 1.67357804
#> 12    10   4 0.79730883
#> 13     7   5 0.86535854
#> 14    11   5 0.41008408
#> 15     7   6 1.26614470
#> 16    11   6 0.81087024
#> 17     7   8 0.14330438
#> 18     7   9 0.38293379
#> 19     8   9 0.23962942
#> 20     7  10 1.01957359
#> 21     8  10 0.87626921
#> 22     7  11 0.45527445