title: R: Smart way to replace column/vector values by multiple rules?
body: <p>I have raw values that I need to recode into 0-1 following few thresholds and calculation. This is how formula looks like:
  <a href="https://i.stack.imgur.com/ZqUqd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZqUqd.png" alt="enter image description here" /></a></p>
  <p>I think this simply says:</p>
  <ul>
  <li>if x &lt; 60 -&gt;  x = 0</li>
  <li>if x &gt; 60 &amp; &lt;= 80 -&gt; x = 0.05*x -3</li>
  <li>if x &gt; 80 -&gt; x  = 1</li>
  </ul>
  <p>And here is my approach:</p>
  <pre><code># V is from 0-600 m3/ha
  set.seed(3)
  V_pine = sample.int(100, 10)  # generate 10 random numbers up to 100
  
  &gt; V_pine
  [1]  5 58 12 36 99 95  8 20 74 55
  
  # Recode values following multiple ifelse statements
  for (i in V_pine){
    if (i &lt;= 60) {
      i &lt;- 0
      } else if (i &gt; 60 &amp; i&lt;= 80) {
        i &lt;- (0.05* i )-3
      } else if (i &gt; 80) {
        i&lt;- 1
      }
    print(i)
  }
  </code></pre>
  <p>Seems that this brings correct results:</p>
  <pre><code>Output: 
  0 0 0 0 1 1 0 0 0.7 0
  </code></pre>
  <p>Yet, as I have another many similar functions/formulas, I wonder if <strong>there is another way how to simplify <code>for loop</code> and <code>ifelse</code> statements?</strong></p>
  <p>My data will be stored in <code>data.frame</code> so use of <code>dplyr</code> and <code>mutate</code> would be great. Thanks for your suggestions!</p>