Question: (Closed) how to create lower or upper triangle distance matrix in R?
0
gravatar for blacktomato27
7 months ago by
United States
blacktomato2720 wrote:

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 • 553 views
ADD COMMENTlink modified 7 months ago by Michael Dondrup44k • written 7 months ago by blacktomato2720

Hello blacktomato27!

We believe that this post does not fit the main topic of this site.

Not a bioinformatics question. Also, this is covered by basic R help. Did you check ?dist ?as.dist or search the r-help for "distance matrix"?

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

ADD REPLYlink modified 7 months ago • written 7 months ago by Michael Dondrup44k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 659 users visited in the last hour