Calculate length of paths between each pair of vertices within tree
Source:R/PathLengths.R
PathLengths.Rd
Given a weighted rooted tree tree
, PathLengths()
returns the distance
from each vertex to each of its descendant vertices.
Arguments
- tree
Original tree of class
phylo
, inPreorder
.- 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()
,
MatchEdges()
,
NSplits()
,
NTip()
,
NodeNumbers()
,
SplitsInBinaryTree()
,
TipLabels()
,
TreeIsRooted()
Examples
tree <- rtree(6)
plot(tree)
add.scale.bar()
nodelabels()
tiplabels()
PathLengths(tree)
#> start end length
#> 1 7 1 2.13032582
#> 2 8 1 2.00095347
#> 3 9 1 1.52283544
#> 4 10 1 0.59876097
#> 5 7 2 2.50773555
#> 6 8 2 2.37836320
#> 7 9 2 1.90024516
#> 8 10 2 0.97617069
#> 9 7 3 1.69600981
#> 10 8 3 1.56663746
#> 11 9 3 1.08851942
#> 12 11 3 0.35672691
#> 13 7 4 1.77075658
#> 14 8 4 1.64138424
#> 15 9 4 1.16326620
#> 16 11 4 0.43147369
#> 17 7 5 0.27758391
#> 18 8 5 0.14821156
#> 19 7 6 0.01307758
#> 20 7 8 0.12937235
#> 21 7 9 0.60749038
#> 22 8 9 0.47811803
#> 23 7 10 1.53156485
#> 24 8 10 1.40219250
#> 25 9 10 0.92407447
#> 26 7 11 1.33928289
#> 27 8 11 1.20991055
#> 28 9 11 0.73179251