title: data.frame with a column containing a matrix in R
body: <p>I'm trying to put some matrices in a dataframe in R, something like : </p>
  
  <pre><code>m &lt;- matrix(c(1,2,3,4), nrow=2, ncol=2)
  df &lt;- data.frame(id=1, mat=m)
  </code></pre>
  
  <p>But when I do that, I get a dataframe with 2 rows and 3 columns instead of a dataframe with 1 row and 2 columns.</p>
  
  <p>Reading the documentation, I have to escape my matrix using I().</p>
  
  <pre><code>df &lt;- data.frame(id=1, mat=I(m))
  
  str(df)
  'data.frame':   2 obs. of  2 variables:
   $ id : num  1 1
   $ mat: AsIs [1:2, 1:2] 1 2 3 4
  </code></pre>
  
  <p>As I understand it, the dataframe contains one row for each row of the matrix, and the mat field is a list of matrix column values.</p>
  
  <p>Thus, how can I obtain a dataframe containing matrices ?</p>
  
  <p>Thanks !</p>