title: R! mutate conditional and list intersect (How many time was a player on the court ?)
body: <p>This is a sport analysis question - How many time was a player on the court ?</p>
  <p>I have a list of players I am interested in</p>
  <p><code>names &lt;- c('John','Bill',Peter')</code></p>
  <p>and a list of actions during multiple matches</p>
  <pre><code>team    &lt;- c('teama','teama','teama','teama','teama','teama','teamb','teamb')
  player1 &lt;- c('John', 'John', 'John', 'Bill', 'Mike', 'Mike', 'Steve', 'Steve')
  player2 &lt;- c('Mike', 'Mike', 'Mike', 'John', 'Bill', 'Bill', 'Peter', 'Bob')
  df &lt;- data.frame(team,player1,player2) 
  </code></pre>
  <p>I want to build a column that will list how many action was the player on the court</p>
  <pre><code>actions_when_player_on_court &lt;- df %&gt;% group_by(team) %&gt;% 
  calculate({nb of observation where the player is either player1 or player2} )
  </code></pre>
  <p>so I end up with a new list like</p>
  <pre><code>actions_when_player_on_court &lt;- c(4,3,1)
  </code></pre>
  <p>so I can create a new DF like this</p>
  <pre><code>new df &lt;- data.frame(names,actions_when_player_on_court)
  </code></pre>
  <p>where John appears 4 times on the court, Bill twice, and Peter once</p>
  <p>I feel I may need to intersect the names and c(player1,player2) especially if</p>
  <ul>
  <li>names are unique - John, Bill and Peter cannot belong to other teams and are unique in df</li>
  <li>I may have 0 to n players on the field so 0 to n column (player1, player2... playern)</li>
  </ul>