title: Manipulating R Data Frames
body: <p>I've currently got two separate data frames, excerpts as per below:</p>
  
  <p>mydata</p>
  
  <pre><code>Player  TG% Pts Team    Opp Yr      Rd  Grnd
  John    56  42  A       1   2015    1   Grnd1
  James   94  64  B       2   2015    1   Grnd2
  Jerry   85  78  C       3   2015    1   Grnd3
  Daniel  97  51  D       4   2015    1   Grnd4
  John    89  61  A       1   2015    1   Grnd2
  James   65  26  B       4   2015    1   Grnd3
  Jerry   73  34  C       3   2015    1   Grnd2
  Daniel  73  40  D       2   2015    1   Grnd2
  John    89  26  A       1   2015    1   Grnd3
  James   92  42  B       3   2015    1   Grnd1
  Jerry   89  25  C       2   2015    1   Grnd2
  Daniel  80  41  D       4   2015    1   Grnd2
  John    73  82  A       3   2015    1   Grnd3
  James   73  41  B       4   2015    1   Grnd3
  Jerry   89  76  C       2   2015    1   Grnd1
  Daniel  91  77  D       1   2015    1   Grnd2
  </code></pre>
  
  <p>round</p>
  
  <pre><code>Team   Opp    Grnd
  A      1      Grnd1
  B      3      Grnd4
  C      4      Grnd2
  D      2      Grnd3
  </code></pre>
  
  <p>What I want to be able to do is manipulate this so that I generate a second data frame as per below</p>
  
  <pre><code>Player   Gms   Avg.Pts   Avg.Last3   Avg.v.Opp   Avg.@.Grnd
  John
  James
  Jerry
  Daniel
  </code></pre>
  
  <p>I know how to do this in Excel, however I'm struggling in R</p>
  
  <p>Gms - total number of games for each individual player (excel would be countif)</p>
  
  <p>Avg.Pts - this is the average of Pts for each Player name (excel would be averageif)</p>
  
  <p>Avg.Last3 - this is the average of Pts for each Player in their last 3 games, note that the data frame is in order with most recent games at the end of the data frame.</p>
  
  <p>Avg.v.Opp - this is the average of Pts for each player against the next opponent as defined in data frame round. For example John plays for team A and his next opponent is Opp 1. (excel would be averageifs)</p>
  
  <p>Avg.@.Grnd - this is the average of Pts for each player at the next ground as defined in data fram round. For example John plays for team A and his next game is held at Grnd1. (excel would be averageifs)</p>
  
  <p>I've tried using dplyr and a number of other options but haven't seemed to successfully put together something that works at this stage. Note that mydata data frame runs to over 10,000+ rows.</p>