title: How to select the rows with maximum values in each group with dplyr?
body: <p>I would like to select a row with maximum value in each group with dplyr.</p>
  
  <p>Firstly I generate some random data to show my question</p>
  
  <pre><code>set.seed(1)
  df &lt;- expand.grid(list(A = 1:5, B = 1:5, C = 1:5))
  df$value &lt;- runif(nrow(df))
  </code></pre>
  
  <p>In plyr, I could use a custom function to select this row.</p>
  
  <pre><code>library(plyr)
  ddply(df, .(A, B), function(x) x[which.max(x$value),])
  </code></pre>
  
  <p>In dplyr, I am using this code to get the maximum value, but not the rows with maximum value (Column C in this case).</p>
  
  <pre><code>library(dplyr)
  df %&gt;% group_by(A, B) %&gt;%
      summarise(max = max(value))
  </code></pre>
  
  <p>How could I achieve this? Thanks for any suggestion.</p>
  
  <pre><code>sessionInfo()
  R version 3.1.0 (2014-04-10)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  
  locale:
  [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
  [3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
  [5] LC_TIME=English_Australia.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] dplyr_0.2  plyr_1.8.1
  
  loaded via a namespace (and not attached):
  [1] assertthat_0.1.0.99 parallel_3.1.0      Rcpp_0.11.1        
  [4] tools_3.1.0        
  </code></pre>