My query question did not produce useful results, and the documentation for ?switch does not tell me how I hope I can get an answer here.
Let's say I have a vector:
cases<- c("one","two","three")
and I want to use the switch statement with these elements as parameters for the switch statement:
switch(input,cases)
The above will only be output if input=1 , in which case it will output:
switch(1,cases) # [1] "one" "two" "three"
Any other parameter will not return anything. The only way I can get the desired behavior is if I explicitly injected the cases into the switch statement as such:
switch(2,"one","two","three") # [1] "two"
I need a behavior in which I can pass a list / vector / as a parameter to switch () and execute the following behavior:
switch(2,cases) # [1] "two"
list vector parameters r switch-statement
Edison orellana
source share