Dear Peter,
   Sorry for bothering you so much. 
   You are right,the function melt() in reshape package returns to full pairs of data. The method you write give exactly what I needed.There's another function, which was written by my friend Guofang, could solve the trouble(see below).
   Thank you very much indeed.
   Best Regards
  Yours Jin
 
read.tri.matrix=function(d) 
{ 
if(is.null(colnames(d)))colnames(d)=paste('V',1:dim(d)[2],sep="") 
if(!is.matrix(d)) as.matrix(d)->d 
m=lower.tri(d) # 提取矩阵下三角 
colnames(m)=row.names(d) 
rownames(m)=row.names(d) 
as.data.frame(m)->m 
stack(m)->xxxx 
xxxx 
names(xxxx)[2]="contrast1" 
rep(colnames(d),dim(d)[1])->xxxx$contrast2 
d=as.data.frame(d) 
stack(d)$values->xxxx$value 
xxxx[xxxx$values,-1]->result 
row.names(result)=NULL 
result 
} 
# by Guofang LIU from IBCAS
 
 
 
 

> Hi, 

>  

> The 'as.data.frame.dist' function requires the mefa package, 

> that's why I wrote the line 'library(mefa)'. This returns the 

> lower triangle only, but it does not return the row/col names. 

>  

> The melt method, however returns the full matrix, not only 

> the lower triangle, see below. 

>  

> Best, 

>  

> Peter 

>  

> -- 

>  

> x <- cbind(rnorm(10), rnorm(10), rnorm(10), rnorm(10)) 

> colnames(x) <- LETTERS[1:4] 

> y <- cor(x) 

>  

> > x <- cbind(rnorm(10), rnorm(10), rnorm(10), rnorm(10)) 

> > colnames(x) <- LETTERS[1:4] 

> > y <- cor(x) 

> > y 

>             A           B          C          D 

> A  1.00000000 -0.01444285  0.3969146  0.1356350 

> B -0.01444285  1.00000000 -0.6151891  0.6649487 

> C  0.39691455 -0.61518910  1.0000000 -0.3847042 

> D  0.13563501  0.66494872 -0.3847042  1.0000000 

> > library(mefa) 

> > as.data.frame(as.dist(y)) 

>   row col        dist 

> 1   2   1 -0.01444285 

> 2   3   1  0.39691455 

> 3   4   1  0.13563501 

> 4   3   2 -0.61518910 

> 5   4   2  0.66494872 

> 6   4   3 -0.38470419 

> > library(reshape) 

> > melt(y) 

>    X1 X2       value 

> 1   A  A  1.00000000 

> 2   B  A -0.01444285 

> 3   C  A  0.39691455 

> 4   D  A  0.13563501 

> 5   A  B -0.01444285 

> 6   B  B  1.00000000 

> 7   C  B -0.61518910 

> 8   D  B  0.66494872 

> 9   A  C  0.39691455 

> 10  B  C -0.61518910 

> 11  C  C  1.00000000 

> 12  D  C -0.38470419 

> 13  A  D  0.13563501 

> 14  B  D  0.66494872 

> 15  C  D -0.38470419 

> 16  D  D  1.00000000 

>  

> On Thu, Jul 23, 2009 at 4:42 PM, Zhang Jinlong<zhangjl@ibcas.ac.cn> wrote: 

> > How to convert matrix to paired list? 

> > Dear lists 

> > 燬uppose I have an correlation matrix of four places named "A","B","C"and"D", as below: 

> > ?燗 ??B ??燙 ?燚 

> > A ?0 ??.5 ?0.2 ?0.8 

> > B ?.5 ?0 ??0.6 ?0.4 

> > C ?.2 ?0.6 ?0 ??0.4 

> > D ?.8 ?0.4 ?0.4 ?0 

> > Is there a function that allows me to generate the paired list like this? 

> > A B 0.5 

> > A C 0.2 

> > A D 0.8 

> > B C 0.6 

> > B D 0.4 

> > C D 0.4 

> > Could you help me if you have an method. Any suggestions will be appreciated. 

> > Thanks 

> > 

> > Jinlong 

> > 

> > 

> > Jin-Long ZHANG 

> > Ph.D. Candidate 

> > Institute of Botany 

> > Chinese Academy of Sciences 

> > Beijing 100093 

> > E-mail: zhangjl@ibcas.ac.cn 

> > 

> > 

> > ???燵[alternative HTML version deleted]] 

> > 

> > _______________________________________________ 

> > R-sig-ecology mailing list 

> > R-sig-ecology@r-project.org 

> > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology 

> > 

> > 

> 

Jin-Long ZHANG 
Ph.D. Candidate
Institute of Botany
Chinese Academy of Sciences
Beijing 100093
E-mail: zhangjl@ibcas.ac.cn 


	[[alternative HTML version deleted]]

