title: getting the x value for the maximum y value
body: <p>I want to extract from a data set the addition, maximum, and average value of a variable (y) jointly with the maximum value of x. I also want to get the x value at maximum y value but I am not able to do so. Tried the max function but gives me an error. </p>
  
  <p>Here is the code I am using:</p>
  
  <pre><code>AUC&lt;-lapply(split(data_example, data_example$class), function(d) sum(d$y))
  max.y&lt;-lapply(split(data_example, data_example$class), function(d) max(d$y))
  max.x&lt;-lapply(split(data_example, data_example$class), function(d) max(d$x))
  auc.mean&lt;-lapply(split(data_example, data_example$class), function(d) mean(d$y))
  x.ymax&lt;-lapply(split(data_example, data_example$class), function(d) 
  max(data_example, data_example$x, select="y"))
  
  data.final&lt;-cbind(AUC,max.y,max.x, auc.mean, x.ymax)
  </code></pre>
  
  <p>Here I uploaded the data for reproduce the example:</p>
  
  <p><a href="http://www.filedropper.com/dataexample_1" rel="nofollow noreferrer">http://www.filedropper.com/dataexample_1</a></p>
  
  <p>Thanks a lot for any help. </p>