[R] compute the associate vector of distances between leaves in a binary non-rooted tree

Arnau Mir Torres arnau.mir at uib.es
Wed Jun 2 14:47:12 CEST 2010


Hello.

I'd like to compute the associate vector of distances between leaves in a binary non-rooted tree. The definition of a distance between two leaves in a binary non-rooted tree is the number of edges in the path joining the two leaves.
I've tried the ape package but I'm unable to find this vector. 
For example, using rtree(5,rooted=F) I've obtained the following tree:

$edge
     [,1] [,2]
[1,]    6    7
[2,]    7    1
[3,]    7    8
[4,]    8    2
[5,]    8    3
[6,]    6    4
[7,]    6    5

$tip.label
[1] "t4" "t3" "t2" "t1" "t5"

$edge.length
[1] 0.9126727 0.2765674 0.4996832 0.7904400 0.8508797 0.8174133 0.9027958

$Nnode
[1] 3


My question is: how to compute the vector of distances between the 5 leaves. This vector is in this case:
v=(d(t1,t2),d(t1,t3),d(t1,t4),d(t1,t5),d(t2,t3),d(t2,t4),d(t2,t5),d(t3,t4),d(t3,t5),d(t4,t5))=(4,4,3,2,2,3,4,3,4,3).


Thanks in advance,

Arnau.
------------------------------------------------------------
Arnau Mir Torres
Edifici A. Turmeda
Campus UIB
Ctra. Valldemossa, km. 7,5
07122 Palma de Mca.
tel: (+34) 971172987
fax: (+34) 971173003
email: arnau.mir at uib.es
URL: http://dmi.uib.es/~arnau
------------------------------------------------------------










More information about the R-help mailing list