[R] as.dist with diagonal unequal zero

Birgit Lemcke birgit.lemcke at systbot.uzh.ch
Wed Oct 10 16:42:09 CEST 2007


Hello and sorry that I still haven´t found a solution for my problem.

I need to extract the lower and upper triangle from a square matrix  
including the diagonal. This diagonal is not zero in that special case.
I tried with as.dist

w<-as.dist(w, diag = TRUE)
 > w
    1  2  3  4  5
1  0
2  2  0
3  3  8  0
4  4  9 14  0
5  5 10 15 20  0

but found no way to keep the diagonal that is in the matrix.

I also tried this but as I expected it makes no difference:

w<-matrix(1:25, ncol=5, nrow=5)
 > upperTriangle(w)<-NA
 > w
      [,1] [,2] [,3] [,4] [,5]
[1,]    1   NA   NA   NA   NA
[2,]    2    7   NA   NA   NA
[3,]    3    8   13   NA   NA
[4,]    4    9   14   19   NA
[5,]    5   10   15   20   25
 > w<-as.dist(w, diag = TRUE)
 > w
    1  2  3  4  5
1  0
2  2  0
3  3  8  0
4  4  9 14  0
5  5 10 15 20  0

Is there perhaps a possibility to give the diagonal as a vector  
within as.dist?

I would be glad if somebody could help me.

Greetings

Birgit

Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
birgit.lemcke at systbot.uzh.ch



More information about the R-help mailing list