
R Language Fundamentals 45
We conclude the discussion of conditional evaluation with the function
switch. The first argument to switch is an expression to evaluate. Any num-
b er of additional arguments can be supplied, and they can be either named
or not. If the value of the expression is numeric, then the corresponding
additional argument is evaluated and returned. If the expression returns a
character value, then the additional argument with the matching name will
b e evaluated and returned. If no argument has a matching name, then the
value of the first unnamed argument is returned.
Partial matching can be problematic when using switch. Since the