title: How to use if..else statement with multiple conditions for vectors?
body: <p>So I have this vector:</p>
  
  <pre><code>Kc167 &lt;- c(7.333333, 24.666667, 31.333333, 65.000000, 59.666667, 74.333333, 72.000000, 38.333333, 73.666667, 87.333333)
  </code></pre>
  
  <p>and I want to categorise each of those numbers into "low", "medium", or "high".</p>
  
  <p>I've written a function that can categorise any number into those categories:</p>
  
  <pre><code>getExpressionLevel &lt;- function(x){
  if (x &lt; 5)
  return ("none")
  else if (x == 5)
  return ("low")
  else if (x &gt; 5 &amp; x &lt; 20)
  return ("low")
  else if (x == 20)
  return ("medium")
  else if (x &gt; 20 &amp; x &lt; 60)
  return("medium")
  else if (x &gt; 60)
  return("high")
  }
  </code></pre>
  
  <p>I've checked that the function works:</p>
  
  <pre><code>getExpressionLevel(55.4)
  [1] "medium"
  </code></pre>
  
  <p>But when I try to use the function on the vector Kc167, it doesn't seem to work:</p>
  
  <pre><code>getExpressionLevel(Kc167)
  [1] "low"
  Warning messages:
  1: In if (x &lt; 5) return("none") else if (x == 5) return("low") else if (x    &gt;  :
    the condition has length &gt; 1 and only the first element will be used
  2: In if (x == 5) return("low") else if (x &gt; 5 &amp; x &lt; 20) return("low") else if (x ==  :
    the condition has length &gt; 1 and only the first element will be used
  3: In if (x &gt; 5 &amp; x &lt; 20) return("low") else if (x == 20) return("medium") else if (x &gt;  :
    the condition has length &gt; 1 and only the first element will be used
  </code></pre>
  
  <p>I've looked around and the ifelse statement works:</p>
  
  <pre><code>ifelse(Kc167&gt;60, "high", "low")
  [1] "low"  "low"  "low"  "high" "high" "high" "high" "low"  "high" "high"
  </code></pre>
  
  <p>But I'm not sure how to add all the remaining conditions into that statement, and why my original function/if... else statement didn't work. Is there something I'm forgetting to add?</p>