Switch Statement In R

[Solved] Switch Statement In R | Matlab - Code Explorer | yomemimo.com
Question : switch in r

Answered by : geut-g

# Following is val1 simple R program  
# to demonstrate syntax of switch.
  
# Mathematical calculation
  
val1 = 6  
val2 = 7
val3 = "s"  
result = switch(  
    val3,  
    "a"= cat("Addition =", val1 + val2),  
    "d"= cat("Subtraction =", val1 - val2),  
    "r"= cat("Division = ", val1 / val2),  
    "s"= cat("Multiplication =", val1 * val2),
    "m"= cat("Modulus =", val1 %% val2),
    "p"= cat("Power =", val1 ^ val2)
)  
    
print(result)

Source : https://www.geeksforgeeks.org/switch-case-in-r/ | Last Update : Thu, 24 Feb 22

Answers related to switch statement in r

Code Explorer Popular Question For Matlab