title: R idiom for switch/case
body: <p>I've got some R code that looks basically like this:</p>
  
  <pre><code>compute.quantiles &lt;- function(mu, type) {
  
    ## 'mu' and 'type' are vectors of the same length
  
    var &lt;- ifelse(type=='a', 6.3523 * mu^2,
           ifelse(type=='b', 234.23 * mu,
           ifelse(type=='c', {s &lt;- 9.8 * ((mu-0.3)/3)^(6/7)+0.19; mu + mu^2/s},
           ifelse(type=='d', 56.345 * mu^1.5,
           ifelse(type=='e', 0.238986 * mu^2,
           ifelse(type=='f', mu + 1.1868823 * mu^2,
           NA ))))))
  
    # ...then do something with var...
  }
  </code></pre>
  
  <p>Some sample input &amp; output:</p>
  
  <pre><code>print(compute.quantiles(2:4, c('c','d','e')))
  [1]   2.643840 292.777208   3.823776
  </code></pre>
  
  <p>That works correctly, but it's kind of ugly with the deep nesting, so I'm wondering if there's a different idiom that works better.  Anyone have a suggestion?  If <code>switch()</code> accepted a vector as its first argument, that would work nicely, but it just takes a scalar.</p>