title: deconstruction of matrix/rearranging columns of matrix
body: <p>Help please !</p>
  
  <p>I have a large matrix and I would like to rearrange the data (or shall i call deconstruction of a martix ?)</p>
  
  <pre><code>    M1   M2   M3   M4  
  L1 "AA" "--" "GG" "CC"
  L2 "AG" "CC" "--" "AA"
  L3 "GG" "CG" "TT" "TT"
  L4 "--" "GG" "CC" "TT"
  L5 "AA" "--" "AA" "CC"
  L6 "AT" "CC" "CT" "AA"
  L7 "TT" "CG" "TA" "CC"
  </code></pre>
  
  <p>the sample data is       </p>
  
  <pre><code>test &lt;- matrix(c("AA", "AG", "GG", "--","AA", "AT", "TT", "--","CC", "CG", "GG", "--","CC", "CG", "GG", "--","TT","CC","AA","CT","TA","CC","AA","TT","TT","CC","AA","CC"),nrow=7)
  row.names(test)= c("L1", "L2", "L3", "L4", "L5", "L6", "L7")
  colnames(test)= c("M1", "M2", "M3", "M4")
  </code></pre>
  
  <p>I need to rearrange and get the data in following format</p>
  
  <pre><code>Line Marker testx
  L1     M1    AA
  L1     M2    --
  L1     M3    GG
  L1     M4    CC
  L2     M1    AG
  L2     M2    CC
  L2     M3    --
  L2     M4    AA
  L3     M1    GG
  L3     M2    CG
  L3     M3    TT
  L3     M4    TT
  .
  .
  .
  </code></pre>
  
  <p>Though I have a lengthy solution (see below), it is hard while handling large dataset. Please help me!</p>
  
  <pre><code>testx&lt;-c(test)
  testx1&lt;-data.frame(testx)
  testx2&lt;-cbind(Line = c("L1","L2","L3","L4","L5","L6","L7"), testx1)
  testx3&lt;-testx2[order(testx2$Line),]
  testx4&lt;-cbind(Marker = c("M1","M2","M3","M4"), testx3)
  testx5 &lt;- testx4[,c("Line", "Marker", "testx")]
  </code></pre>