title: How to extract values between adjacent variables in a correlation matrix in R?
body: <p>I have got huge correlation matrix, but the following is just an example: </p>
  
  <pre><code>    set.seed(1234)
  
  corrmat &lt;- matrix(round (rnorm (36, 0, 0.3),2), ncol=6) 
  rownames (corrmat) &lt;- colnames (corrmat) &lt;- c("A", "b1", "b2", "C", "L", "ctt")
  diag(corrmat) &lt;- NA 
  corrmat[upper.tri (corrmat)] &lt;- NA 
              A    b1    b2     C     L ctt
      A      NA    NA    NA    NA    NA  NA
      b1   0.08    NA    NA    NA    NA  NA
      b2   0.33 -0.17    NA    NA    NA  NA
      C   -0.70 -0.27 -0.03    NA    NA  NA
      L    0.13 -0.14 -0.15 -0.13    NA  NA
      ctt  0.15 -0.30 -0.27  0.14 -0.28  NA
  
  &gt; melt(corrmat)
  
         X1  X2  value
      1    A   A    NA
      2   b1   A  0.08
      3   b2   A  0.33
      4    C   A -0.70
      5    L   A  0.13
      6  ctt   A  0.15
      7    A  b1    NA
      8   b1  b1    NA
      9   b2  b1 -0.17
      10   C  b1 -0.27
      11   L  b1 -0.14
      12 ctt  b1 -0.30
      13   A  b2    NA
      14  b1  b2    NA
      15  b2  b2    NA
      16   C  b2 -0.03
      17   L  b2 -0.15
      18 ctt  b2 -0.27
      19   A   C    NA
      20  b1   C    NA
      21  b2   C    NA
      22   C   C    NA
      23   L   C -0.13
      24 ctt   C  0.14
      25   A   L    NA
      26  b1   L    NA
      27  b2   L    NA
      28   C   L    NA
      29   L   L    NA
      30 ctt   L -0.28
      31   A ctt    NA
      32  b1 ctt    NA
      33  b2 ctt    NA
      34   C ctt    NA
      35   L ctt    NA
      36 ctt ctt    NA
  </code></pre>
  
  <p>What I am looking is correlation values between adjacent only - means that between A-b1, b1-b2,b2-C, C-L, L-ctt (in the order in column). I need to remove other values and NA. Thus expected will be:</p>
  
  <pre><code>        X1   X2  value
      2   b1   A   0.08
      9   b2   b1 -0.17
      16   C   b2  -0.03
      23   L   C  -0.13
      30  ctt  L  -0.28
  </code></pre>
  
  <p>Thus they are in: <code>A-b1-b2-C-L-ctt</code> order. </p>
  
  <p>Is there a easy way to filter it ? </p>