Reshape each row of a data.frame to be a matrix in R
<p>I am working with the hand-written zip codes dataset. I have loaded the dataset like this:</p>

<pre><code>digits &lt;- read.table("./zip.train",
                     quote            = "",
                     comment.char     = "",
                     stringsAsFactors = F)
</code></pre>

<p>Then I get only the ones:</p>

<pre><code>ones &lt;- digits[digits$V1 == 1, -1]
</code></pre>

<p>Right now, in <code>ones</code> I have 442 rows, with 256 column. I need to transform each row in <code>ones</code> to a 16x16 <code>matrix</code>. I think what I am looking for is a list of 16x16 matrix like the ones in this question:</p>

<p><a href="https://stackoverflow.com/questions/13765144/how-to-create-a-list-of-matrix-in-r">How to create a list of matrix in R</a></p>

<p>But I tried with my data and did not work.</p>

<p>At first I tried <code>ones &lt;- apply(ones, 1, matrix, nrow = 16, ncol = 16)</code> but is not working as I thought it was. I also tried <code>lapply</code> with no luck.</p>