title: R apply factor objects
body: <p>I would like to <code>apply</code> the <code>factor</code> function over each row of an <code>R</code> dataframe.  So, I'd like to get a array of <code>factor</code> type objects.  However, when I:</p>
  <pre><code>apply(df, 1, factor)
  </code></pre>
  <p>I don't get that thing.  What am I misunderstanding about <code>apply</code> or <code>factor</code>?</p>
  <p>data:</p>
  <pre><code>dput(df)
  
  structure(list(flip..1. = c(&quot;heads&quot;, &quot;heads&quot;), flip..2. = c(&quot;tails&quot;, &quot;heads&quot;), flip..3. = c(&quot;heads&quot;, &quot;tails&quot;), flip..4. = c(&quot;tails&quot;, &quot;tails&quot;), flip..5. = c(&quot;heads&quot;, &quot;tails&quot;), flip..6. = c(&quot;tails&quot;, &quot;heads&quot;), flip..7. = c(&quot;heads&quot;, &quot;heads&quot;), flip..8. = c(&quot;heads&quot;, &quot;tails&quot;), flip..9. = c(&quot;tails&quot;, &quot;tails&quot;), flip..10. = c(&quot;heads&quot;, &quot;heads&quot;)), class = &quot;data.frame&quot;, row.names = c(NA, -2L))
  </code></pre>
  <p>code:</p>
  <pre><code>rowwise_factors &lt;- apply(df, 1, factor)
  # rowwise_factors seems to be a matrix of characters, or some such, not an array of factor objects.
  </code></pre>
  <p>expected_output:</p>
  <pre><code>dput(expected)
  
  list(structure(c(flip..1. = 1L, flip..2. = 2L, flip..3. = 1L, flip..4. = 2L, flip..5. = 1L, flip..6. = 2L, flip..7. = 1L, flip..8. = 1L, flip..9. = 2L, flip..10. = 1L), .Label = c(&quot;heads&quot;, &quot;tails&quot;), class = &quot;factor&quot;), 
  structure(c(flip..1. = 1L, flip..2. = 1L, flip..3. = 2L, 
  flip..4. = 2L, flip..5. = 2L, flip..6. = 1L, flip..7. = 1L, 
  flip..8. = 2L, flip..9. = 2L, flip..10. = 1L), .Label = c(&quot;heads&quot;, &quot;tails&quot;), class = &quot;factor&quot;))
  </code></pre>
  <p>What am I misunderstanding here, and also how do I make this work?</p>
  <p>W.R.T. CLOSE: these don't answer my question, as I would like to apply this ROW-WISE, not COLUMN-WISE.  Simply transposing my data.frame doesn't make the cited solutions work.</p>