title: How to remove only one instance of a duplicate value in a vector in R?
body: <p>Let's consider a vector of numeric values "x". Some values may be duplicates. I need to remove the max value one by one until x is empty.</p>
  
  <p>Problem, if I use:</p>
  
  <pre><code>x &lt;- x[x != max(x)]
  </code></pre>
  
  <p>It removes all duplicates equal to the maximum. I want to remove only one of the duplicates. So until now, I do:</p>
  
  <pre><code>max.x &lt;- x[x == max(x)]
  max.x &lt;- max.x[1:length(max.x) - 1]
  x &lt;- c(x[x != max(x)], max.x)
  </code></pre>
  
  <p>But this is far from computationally efficient, and I'm not good enough at R to find the right way to do this. Can someone has a better trick?</p>
  
  <p>Thanks</p>