Off topic:how to create lower or upper triangle distance matrix in R?
0
0
Entering edit mode
3.2 years ago

Hi to all Good Afternoon I got data like this

    1   2   3   4   5
A   0.1 0.2 0.3 0.5 0.6
B   0.7 0.8 0.9 1   1.1
C   1.2 1.3 1.4 1.5 1.6
D   1.7 1.8 1.9 2   2.1
E   2.2 2.3 2.4 2.5 2.6


and now I want to create lower triangle matrix like this

    1   2   3   4   5   A   B   C   D   E
1   0
2   0.1 0
3   0.2 0.1 0
4   0.4 0.3 0.2 0
5   0.5 0.4 0.3 0.1 0
A   0.1 0.2 0.3 0.5 0.6 0
B   0.7 0.8 0.9 1   1.1 0.6 0
C   1.2 1.3 1.4 1.5 1.6 1.1 0.5 0
D   1.7 1.8 1.9 2   2.1 1.6 1   0.5 0
E   2.2 2.3 2.4 2.5 2.6 2.1 1.5 1   0.5 0


I just deducted distance between 2 from 1 from first table to get genetic distance between 1 and 2 (0.2 - 0.1=0.1) and like this I did for rest of the entries and I do not know doing like this is correct or not?, after doing calculation like that made lower triangle matrix. I tried like this in R x <- read.csv("AD2.csv", head = FALSE, sep = ",") b<-lower.tri(b, diag = FALSE) but I am getting only TRUE and FALSE as output not like distance matrix. can any one help to solve this problem and here is link to my example data https://www.dropbox.com/s/5yjo4w73pwlv51g/distance%20matrix.xlsx?dl=0 any help in this regard is highly appreciated Thanks in advance With Kind Regards

R • 1.9k views