title: R: How to convert a matrix to a paiwise table
body: <p>Here is my data:</p>
  
  <pre><code># dput(df.test)
  df.test &lt;- structure(c(-0.137235615851502, -0.344759702428411, -0.500276100624054, 
     0.122807828503122, -0.130924743022576, -0.0542704064363563, 
  0.039391925478255, 
  0.243784953115516, 0.0883309513092308, 0.0675697778557469, -1.67154143640331, 
  -0.74586999467227, -0.918218758788072, -0.737501839137725, -0.695982777807731, 
  -0.261610590965684, 0.239670548613769, -1.34877698647918, -0.504798658275852, 
  -1.24572197862728, -0.486583609683047, 0.980236244566918, -0.116770013736538, 
  0.920159170273464, -0.10736672150312, -8.89160990468917e-05, 
  0.348988243479406, 0.617914802582402, 0.656439423147673, -0.354915972214178, 
  -1.18814282565241, 0.212586529711788, -1.34854604751212, -0.998557851421873, 
  -0.74181104373128, -0.0170527993337153, 0.30534134631944, 0.210602547719027, 
  0.114868692300985, -0.241156345365843, 0.0409503041301629, -0.141247112486854, 
  1.13468918763325, 1.10190429633177, 0.974719892082623, 0.308013449851554, 
  0.325430402505505, 0.425943042146858, -0.416100998370807, -0.849819133980983, 
  0.0124994038349017, 0.151245516103462, -0.761816247724478, 0.121277476907768, 
  -0.700493571686297, 0.753720053677532, 0.791729047876451, 0.586569855488007, 
  0.640685549845673, 0.307310834638093, -0.777681832695071, -0.276115846072197, 
  0.262603441790964, 0.150279479678085, -0.557115414705732, -0.396898449486936, 
  0.03389047449877, -0.190355621208492, -1.21791954244884, -2.28188861387015, 
  -0.0081105663876241, -0.180463433442979, -0.565919038488081, 
  -0.115657183862188, -0.407493033392482, 0.715409910014252, 0.623893468033432, 
  0.647563699377912, 0.546007665695014, 0.490398233809793, -0.43324574501806, 
  -0.871876793486434, -1.81145751495322, -1.3005509034921, -1.40243116901666, 
  0.139281915052797, 0.347898750603362, 0.282702203690958, -0.431253116344841, 
  0.16440956798378, -0.750075962031573, -0.309894842197134, -1.24408212327799, 
  -0.930479637220003, -0.840163477364932, -0.256433477655579, 0.223612598289618, 
  -0.328115459523084, -0.626812976718478, -0.261546831009025, -0.20786453729735, 
  0.106078100341805, -0.910838639149023, -1.1180854962578, -0.792044461919501, 
  0.316396765486493, 0.489473500044217, 0.0590916030923373, -0.143245152074595, 
  -0.921100483491182, -1.19334272057547, -1.66157203208889, -1.81669210944741, 
  -1.20176956150734, -2.18243725854221, -0.27101382554528, -0.0130954129461394, 
  -0.171464277285432, -0.460820150747689, 0.395113463050538, -0.16459858805902, 
  0.615593737927043, -2.46533984338165, 0.353933137376644, -0.507538015140642, 
  0.245268990334321, 0.581619257906453, 0.456324105305399, 0.206354684883677, 
  -0.11125681492886, -0.199966930303893, -0.199966930303893, -0.199966930303893, 
  -0.199966930303893, -0.199966930303893, -0.199966930303893, -0.19966930303893, 
  -0.199966930303893, -0.199966930303893, -0.199966930303893, -0.788074384147715, 
  0.0131180883069579, -1.03064824913784, 0.13771416741358, -1.8513993571836, 
  -0.0436516438935982, 0.261575983666598, 0.148634504258857, -0.249427198022059, 
  -0.32031130009525, -0.765726570026253, -0.595126233138136, -1.44658213011755, 
  -0.269091504644174, -2.08351239429702, 0.0900973816555721, 0.314778853798272, 
  0.146568932407963, -0.803030173606724, -0.56793087783812, 0.622483630669056, 
  0.56646658059064, 0.268151149922434, 0.791542756272689, -0.432658297428692, 
  0.164932324763406, 0.0697834862042083, -0.0354098313891721, -0.049985903348964, 
  -0.247944070199659, 0.344109859832212, 1.04994304288576, 0.884040197128818, 
  1.37547529693912, -0.606965309241119, 0.136459509819662, 0.522406532751529, 
  0.429139781850674, -0.115182675707781, -0.602276293951237, -0.41896069616702, 
  0.438616012513544, -0.0412858273853989, 0.670844298708518, -1.2210053871905, 
  0.0602539820433709, 0.735766132108792, 0.433929205193091, -0.246259174844229, 
  -0.923911812392792, -0.0946173725933034, -0.0710377929016193, 
  -1.98665869018574, -0.198825160900287, -2.07196831254035, 0.732524985440316, 
  0.836338909647763, 0.864143191972808, 0.482735975495422, 0.371247082955781 ), .Dim = c(10L, 20L), .Dimnames = list(c("PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML", 
  "PA14_EM_1-1_B-1_P1-B-1_01_1846.mzXML",
  "PA14_EM_1-1_D-10_P1-D-10_01_1887.mzXML", 
  "PA14_EM_1-1_D-9_P1-D-9_01_1886.mzXML",
  "PA14_EM_1-1_E-8_P1-E-8_01_1903.mzXML", 
  "PA14_EM_1-2_A-12_P1-A-12_01_1974.mzXML",
  "PA14_EM_1-2_A-1_P1-A-1_01_1963.mzXML", 
  "PA14_EM_1-2_A-3_P1-A-3_01_1965.mzXML",
  "PA14_EM_1-2_B-12_P1-B-12_01_1986.mzXML", 
  "PA14_EM_1-2_C-3_P1-C-3_01_1989.mzXML"), c("HPh_feats", "PhCN_feats", 
  "PhCA_feats", "PYO_feats", "HHQ_feats", "PQS_feats", "NHQ_feats", 
  "C9PQSdb_feats", "C9PQS_feats", "UHQdb_feats", "UHQ_feats",
  "C11PQSdb_feats",  "RC8C10_feats", "RC10C10_feats", "RC10C12db_feats",
  "RC10C12_feats",  "RRC10C10_feats", "RRC10C12db_feats",
  "RRC10C12_feats", "PCH_feats" )))
  </code></pre>
  
  <p>I am calculating the pairwise corrlation of each row and would like the output in a pairwise table.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>library(Hmisc) 
  df.corr.test&lt;-rcorr(t(df.test))
  df.corr.pw.test&lt;-as.data.frame(t(combn(rownames(df.corr.test$r),2)))
  df.corr.pw.test$corr&lt;-unlist(df.corr.test$r[upper.tri(df.corr.test$r)])
  </code></pre>
  
  <p>However, there seems to be an error as the pairwise output table contains the wrong numbers.</p>
  
  <pre><code>&gt; df.corr.test$r[1:5,1:5]
                                         PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML
  PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML                              1.0000000
  PA14_EM_1-1_B-1_P1-B-1_01_1846.mzXML                                0.5554451
  PA14_EM_1-1_D-10_P1-D-10_01_1887.mzXML                              0.4153940
  PA14_EM_1-1_D-9_P1-D-9_01_1886.mzXML                                0.6128278
  PA14_EM_1-1_E-8_P1-E-8_01_1903.mzXML                                0.3815668
  </code></pre>
  
  <p>Here is the output as a pairwise table:</p>
  
  <pre><code>    &gt; head(df.corr.pw.test)
                                        V1                                     V2      corr
  1 PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML   PA14_EM_1-1_B-1_P1-B-1_01_1846.mzXML 0.5554451
  2 PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML PA14_EM_1-1_D-10_P1-D-10_01_1887.mzXML 0.4153940
  3 PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML   PA14_EM_1-1_D-9_P1-D-9_01_1886.mzXML 0.4064743
  4 PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML   PA14_EM_1-1_E-8_P1-E-8_01_1903.mzXML 0.6128278
  5 PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML PA14_EM_1-2_A-12_P1-A-12_01_1974.mzXML 0.7091195
  6 PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML   PA14_EM_1-2_A-1_P1-A-1_01_1963.mzXML 0.6917794
  </code></pre>
  
  <p>The thrid line is an error:</p>
  
  <pre><code>3 PA14_EM_1-1_A-10_P1-A-10_01_1839.mzXML   PA14_EM_1-1_D-9_P1-D-9_01_1886.mzXML 0.4064743
  </code></pre>
  
  <p>The corr value should be 0.6128 .
  Am I using combn correctly? 
  any help is appreciated.
  thanks</p>