title: Create dataframe from a matrix
body: <p>How to get a data frame with the same data as an already existing matrix has?</p>
  
  <p>A simplified example of my matrix:</p>
  
  <pre><code>mat &lt;- matrix(c(0, 0.5, 1, 0.1, 0.2, 0.3, 0.3, 0.4, 0.5),
                ncol = 3, nrow = 3,
                dimnames = list(NULL, c("time", "C_0", "C_1")))
  
  &gt; mat
       time C_0 C_1
  [1,]  0.0 0.1 0.3
  [2,]  0.5 0.2 0.4
  [3,]  1.0 0.3 0.5
  </code></pre>
  
  <p>I would like to create a data frame that looks like this:</p>
  
  <pre><code>     name   time   val
  1    C_0    0.0    0.1
  2    C_0    0.5    0.2
  3    C_0    1.0    0.3
  4    C_1    0.0    0.3
  5    C_1    0.5    0.4
  6    C_1    1.0    0.5
  </code></pre>
  
  <p>All my attempts are quite clumsy, for example:</p>
  
  <pre><code>data.frame(cbind(c(rep("C_1", 3), rep("C_2", 3)),
                   rbind(cbind(mat[,"time"], mat[,"C_0"]),
                         cbind(mat[,"time"], mat[,"C_1"]))))
  </code></pre>
  
  <p>Does anyone have an idea of how to do this more elegantly? Please note that my real data has a few more columns (40 columns).</p>