title: select maximum row value by group
body: <p>I've been trying to do this with my data by looking at other posts, but I keep getting an error. My data <code>new</code> looks like this:</p>
  
  <pre><code>id  year    name    gdp
  1   1980    Jamie   45
  1   1981    Jamie   60
  1   1982    Jamie   70
  2   1990    Kate    40
  2   1991    Kate    25
  2   1992    Kate    67
  3   1994    Joe     35
  3   1995    Joe     78
  3   1996    Joe     90
  </code></pre>
  
  <p>I want to select the row with the highest year value by id. So the wanted output is:</p>
  
  <pre><code>id  year    name    gdp
  1   1982    Jamie   70
  2   1992    Kate    67
  3   1996    Joe     90
  </code></pre>
  
  <p>From <a href="https://stackoverflow.com/questions/9718711/selecting-rows-which-contain-daily-max-value-in-r">Selecting Rows which contain daily max value in R</a> I tried the following but did not work</p>
  
  <pre><code>ddply(new,~id,function(x){x[which.max(new$year),]})
  </code></pre>
  
  <p>I've also tried </p>
  
  <pre><code>tapply(new$year, new$id, max)
  </code></pre>
  
  <p>But this didn't give me the wanted output.</p>
  
  <p>Any suggestions would really help!</p>