title: Calculate frequency of values in rows (calculating number of first, second, and third places in a league table)
body: <p>I have a data frame for a sports league (actual data is ~70 teams and ~10 games):</p>
  <pre><code>data &lt;- data.frame(team = c(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;),
                     g1_placement = c(1,2,3,4), 
                     g2_placement = c(1,3,4,2),
                     g3_placement = c(2,1,4,3))
  </code></pre>
  <p>Where <code>team</code> is the team name, <code>g*_placement</code> is the teams placement in games 1-3:</p>
  <pre><code>  team g1_placement g2_placement g3_placement
  1    a            1            1            2
  2    b            2            3            1
  3    c            3            4            4
  4    d            4            2            3
  </code></pre>
  <p>I want to calculate the number of first, second, and third places for each time, the final result would be:</p>
  <pre><code>  team g1_placement g2_placement g3_placement first second third
  1    a            1            1            2     2      1     0
  2    b            2            3            1     1      1     1
  3    c            3            4            4     0      0     1
  4    d            4            2            3     0      1     1
  </code></pre>