title: gather() per grouped variables in R for specific columns
body: <p>I have a long data frame with players' decisions who worked in groups. 
  I need to convert the data in such a way that each row (individual observation)  would contain all group members decisions (so we basically can see whether they are interdependent). </p>
  
  <p>Let's say the generating code is:</p>
  
  <pre><code>group_id &lt;- c(rep(1, 3), rep(2, 3))
  player_id &lt;- c(rep(seq(1, 3), 2))
  player_decision &lt;- seq(10,60,10)
  player_contribution &lt;- seq(6,1,-1)
  df &lt;-
    data.frame(group_id, player_id, player_decision, player_contribution)
  </code></pre>
  
  <p>So the initial data looks like:</p>
  
  <pre><code>  group_id player_id player_decision player_contribution
  1        1         1              10                   6
  2        1         2              20                   5
  3        1         3              30                   4
  4        2         1              40                   3
  5        2         2              50                   2
  6        2         3              60                   1
  </code></pre>
  
  <p>But I need to convert it to <code>wide</code> per each group, but only for some of these variables, (in this example specifically for <code>player_contribution</code>, but in such a way that the rest of the data remains. So the head of the converted data would be:</p>
  
  <pre><code>data.frame(group_id=c(1,1), 
             player_id=c(1,2),
             player_decision=c(10,20),
             player_1_contribution=c(6,6),
             player_2_contribution=c(5,5),
             player_3_contribution=c(4,6)
             )
  </code></pre>
  
  <pre><code>  group_id player_id player_decision player_1_contribution player_2_contribution player_3_contribution
  1        1         1              10                     6                     5                     4
  2        1         2              20                     6                     5                     6
  </code></pre>
  
  <p>I suspect I need to <code>group_by</code> in <code>dplyr</code> and then somehow <code>gather</code> per group but only for <code>player_contribution</code> (or a vector of variables). But I really have no clue how to approach it. Any hints would be welcome!</p>