title: R: switch statement with multiple lines
body: <p>In R: I have a matrix with one column classified by 8 types: a, b, c, d, e, f, g, h. I need to do different computations for each type using the data in the other columns. I want to use a switch() function to automate the looping through each type and state the difference calculations for each type; HOWEVER, everything I am seeing online only shows examples of the syntax for one line switch computations for each switch. </p>
  
  <p>Here is an example using the code provided in the switch() help. I know that mean() is a function, but let's just say for this example, that it isn't a function, because I just want to illustrate that I do not know the syntax (and it's not clearly stated in my research online):</p>
  
  <pre><code>centre &lt;- function(x, type) {
    switch(type,
       mean = {
             total.sum&lt;-sum(type)
             mean = total.sum/length(type)
       },
       median = median(x),
       trimmed = mean(x, trim = .1))
  }
  </code></pre>