title: In R, how to select rows based on a statistic of a column attribute?
body: <p>My table has thousands of rows  classified by 400 classes, and a dozen columns. </p>
  
  <p>The ideal outcome will be a table with 400 rows (1 row for each class) based on the max value of column "z", and containing all the original columns.</p>
  
  <p>Here is an example of my data, and I need only the 2nd, 4th, 7th, 8th rows extracted in this example, using R. </p>
  
  <blockquote>
  <pre><code>     x           y         z    cluster 
  1  712521.75  3637426.49  19.46   12 
  2  712520.69  3637426.47  19.66   12  *
  3  712518.88  3637426.63  17.37   225
  4  712518.4   3637426.48  19.42   225 *
  5  712517.11  3637426.51  18.81   225
  6  712515.7   3637426.58  17.8    17 
  7  712514.68  3637426.55  18.16   17  *
  8  712513.58  3637426.55  18.23   50  *
  9  712512.1   3637426.62  17.24   50
  10 712513.93  3637426.88  18.08   50 
  </code></pre>
  </blockquote>
  
  <p>I have tried many different combinations including these:</p>
  
  <blockquote>
  <pre><code>  tapply(data$z, data$cluster, max)       # returns only the max value and cluster columns
    which.max(data$z)         # returns only the index of the max value in the entire table
  </code></pre>
  </blockquote>
  
  <p>I have also read through the plyr package, but did not find a solution.</p>