Switch case statements are a substitute for long if statements that compare a variable to several integral values. Switch case in R is a multiway branch statement. It allows a variable to be tested for equality against a list of values.
Switch statement follows the approach of mapping and searching over a list of values. If there is more than one match for a specific value, then the switch statement will return the first match found of the value matched with the expression.
switch(expression, case1, case2, case3....)
Here, the expression is matched with the list of values and the corresponding value is returned.
Important Points about Switch Case Statements:
- An expression type with character string always matched to the listed cases.
- An expression which is not a character string then this exp is coerced to integer.
- For multiple matches, the first match element will be used.
- No default argument case is available there in R switch case.
- An unnamed case can be used, if there is no matched case.
multiplication = 42NULL
- How to use a switch case 'or' in PHP?
- Golang Program to Show the Duplicate Case Error in Switch Statement
- Switch Case with Break in For Loop in Golang
- Scala | Case Class and Case Object
- Golang Program that uses String Switch
- What is ISL(Inter-Switch Link)?
- Golang Program that switch on floating-point numbers
- Golang program that uses switch, multiple value cases
- What is SMPS(Switch Mode Power Supply)?
- Decision Making in R Programming - if, if-else, if-else-if ladder, nested if-else, and switch
- case command in Linux with examples
- Case conversion of a String in R Language - toupper(), tolower(), casefold() and cartr() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.