title: R - data frame switch rows and columns
body: <p>I have data frame looking like this:</p>
  
  <pre><code>category fan_id likes
  A     10702397  1
  B     10702397  4
  A     35003154  1
  B     35003154  1
  C     35003154  2 
  </code></pre>
  
  <p>I'd like to convert it into a following data frame</p>
  
  <pre><code>fan_id   A B C
  10702397 1 4 0
  35003154 1 1 2
  </code></pre>
  
  <p>The only way that I can think of is looping over the data frame and constructing another manually but it seems like there has to be a better way.</p>
  
  <p>It seems like I want to the opposite of what was asked here <a href="https://stackoverflow.com/questions/16232192/switch-column-to-row-in-a-data-frame">Switch column to row in a data.frame</a></p>