The ifelse() function and if-else statements can be used to evaluate one of two expressions or chunks of code depending upon a Boolean logical condition. However, these constructions must be chained together to choose between three or more expressions or code chunks to evaluate. The switch() function provides a better alternative. It can be used to pick one of several expressions to return based upon a numerical or character input. In this video we introduce the switch() function and illustrate its use with both numeric and character inputs.
While you can program in R without ever using the switch() function, for certain conditional execution tasks it is much more convenient than chaining together if-else statements and you should get in the habit of using it. So you should definitely learn this function. This video will help you learn it more quickly, so I strongly encourage you to watch.