title: Remove duplicates based on 2nd column condition
body: <p>I am trying to remove duplicate rows from a data frame based on the max value on a different column</p>
  
  <p>So, for the data frame:</p>
  
  <pre><code>df&lt;-data.frame (rbind(c("a",2,3),c("a",3,4),c("a",3,5),c("b",1,3),c("b",2,6),c("r",4,5))
    colnames(df)&lt;-c("id","val1","val2")
  
  id val1 val2
  
    a    2    3
  
    a    3    4
  
    a    3    5
  
    b    1    3
  
    b    2    6
  
    r    4    5
  </code></pre>
  
  <p>I would like to keep remove all duplicates by id with the condition that for the corresponding rows they do not have the maximum value for val2. </p>
  
  <p>Thus the data frame should become:</p>
  
  <pre><code>  a    3    5
  
    b    2    6
  
    r    4    5
  </code></pre>
  
  <p>-> remove all a duplicates but keep row with the max value for df$val2 for subset(df, df$id=="a") </p>