R Switch Case.
-
Switch case in R is a branch statement. It allows variable to be tested for equality against a list of values
-
In case of multiple matches, the first match element will be used.
-
No default argument case.
Syntax of Switch case -
switch(expression, case1, case2, case3....)
Example
val <- switch(
2,
"Val-1" ,
"Val-2" ,
"Val-3"
)
print(val)
Output
[1] "Val-2"