Using sapply with switch
r
Solution
I'll make it an answer then, you can just do:
mapping[test]
# AA bb
# 5 7
Problem
Lets say I have the following case: I am trying to apply a switch statement to each term in test where `test = c("AA","bb")` and `mapping = c("AA"=5,"bb"=7)` If I do ``` sapply(test, switch, mapping ) ``` I get ``` AA bb AA 5 5 bb 7 7 ``` instead of `c(5,7)` like I want. Is there any way to modify `sapply(test,switch,...)` such that the first 2 arguments are still test and switch and I am able to pass in a vector for the mapping?