Liam & Maria,

Liam J. Revell wrote on 09/02/2010 04:24:
Try this:

# given an object of class "phylo" called tree

# 1. create vector for terminal edge lengths
terminal.edges<-matrix(NA,length(tree$tip.label));

# 2. copy terminal branches into vector
terminal.edges<-tree$edge.length[tree$edge[1:(2*length(tree$tip.label)-2),2]<=length(tree$tip.label)];

The above will work if 'tree' is rooted and fully dichotomous. I'd rather do this:

# identifies your terminal branches with TRUE:
terms <- tree$edge[, 2] <= Ntip(tree)
terminal.edges <- tree$edge.length[terms]

Step 2 will erase a possibly existing 'terminal.edges' object, so step 1
is not needed.

# 3. label terminal branches by tip label
names(terminal.edges)<-tree$tip.label;

This might not work in all cases because the tips are not always ordered
1, 2, 3, ... along the second column of the edge matrix. So you may
reorder your labels first:

names(terminal.edges) <- tree$tip.label[tree$edge[terms, 2]]

HTH

Emmanuel

I think that should work.

- Liam

Liam J. Revell
NESCent, Duke University
web: http://anolis.oeb.harvard.edu/~liam/
NEW email: lrev...@nescent.org



mgavil2 wrote:
Dear All

I am trying to find a way to get a vector of only the terminal branch length
for species in a phylogeny, but cant seem to find a way

any suggestions?

Best,

Maria Mercedes


_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo


--
Emmanuel Paradis
IRD, Montpellier, France
  ph: +33 (0)4 67 16 64 47
 fax: +33 (0)4 67 16 64 40
http://ape.mpl.ird.fr/

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

Reply via email to