1 ## branching.times.R (2009-05-10)
3 ## Branching Times of a Phylogenetic Tree
5 ## Copyright 2002-2009 Emmanuel Paradis
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
10 branching.times <- function(phy)
12 ### the tree must be in cladewise order
13 if (!inherits(phy, "phylo"))
14 stop('object "phy" is not of class "phylo"')
15 n <- length(phy$tip.label)
17 xx <- numeric(phy$Nnode)
18 interns <- which(phy$edge[, 2] > n)
19 ## we loop only on the internal edges, this assumes
20 ## that `xx' is already set with 0
22 xx[phy$edge[i, 2] - n] <- xx[phy$edge[i, 1] - n] + phy$edge.length[i]
23 depth <- xx[phy$edge[N, 1] - n] + phy$edge.length[N]
26 if (is.null(phy$node.label)) (n + 1):(n + phy$Nnode) else phy$node.label