title: How do I recode values in a table based on frequency of the value
body: <p>I'm trying to recode values with freq = 1 to the next band.</p>
  <p>Using iris dataset as an example.</p>
  <pre><code>iris %&gt;% select(Sepal.Length) %&gt;% table %&gt;% as.data.frame()
  </code></pre>
  <p>We can see from the table that the values 7.9, 7.6, 7.4, 7.3, 7.1, 7, 5.3, 4.3 have frequencies of 1.</p>
  <p>Currently, I'm manually recoding the single frequencies to the next lower band and the smallest band to the on above it.</p>
  <pre><code>iris$Sepal.Length[iris$Sepal.Length == &quot;7.9&quot;] = &quot;7.7&quot;
  iris$Sepal.Length[iris$Sepal.Length == &quot;7.6&quot;] = &quot;7.4&quot;
  iris$Sepal.Length[iris$Sepal.Length == &quot;7.3&quot;] = &quot;7.2&quot;
  iris$Sepal.Length[iris$Sepal.Length == &quot;7.1&quot;] = &quot;7&quot;
  iris$Sepal.Length[iris$Sepal.Length == &quot;5.3&quot;] = &quot;5.2&quot;
  iris$Sepal.Length[iris$Sepal.Length == &quot;4.5&quot;] = &quot;4.4&quot;
  iris$Sepal.Length[iris$Sepal.Length == &quot;4.3&quot;] = &quot;4.4&quot;
  </code></pre>
  <p>Would like to seek your advice on how to write a function which does the following:</p>
  <ol>
  <li>Check each value from the biggest value downwards for Freq = 1</li>
  <li>When a value with Freq = 1 is identified, mutate it's value to the next lower value.</li>
  <li>Repeat the Check from the top.</li>
  <li>If the last value (Smallest value) has Freq = 1, mutate it's value to the next higher value.</li>
  <li>Finish the function when there are no more Freq = 1.</li>
  </ol>