title: How to do ifelse statements in R for more than two options?
body: <p>Suppose I have this:</p>
  <pre><code>df$color &lt;- ifelse(df$value == 1, &quot;black&quot;, &quot;red&quot;)
  </code></pre>
  <p>I.e. if the <code>value == 1</code> in the value column of <code>df</code>, then we have black, otherwise we have red. This is fine.</p>
  <p>But, how can I do this for values more than 2?</p>
  <p>For instance, I want something like:</p>
  <pre><code>df$color &lt;- if(df$name == 'Greg', 'red'), if(df$name == 'Tom', 'black'), 
    if(df$name == 'Beth', 'white')
  </code></pre>
  <p>But this syntax doesn't look right. Does anyone know how I can do this?</p>