TITLE(switch @@ Select One of a List of Alternatives)
USAGE(
switch(EXPR, DOTS)
)
ALIAS(switch)
ARGUMENTS(
ARG( EXPR @@ an expression that evaluates to a number or a character string)
ARG( DOTS @@ the list of alternatives, given explicitly)
)
DESCRIPTION(
LANG(switch) evaluates LANG(EXPR) if the value is an integer between
1 and LANG(nargs()-1) then the corresponding element of LANG(DOTS) is
evaluated and the result returned.
If LANG(EXPR) returns a character string then that string is used to
match the names of the elements in LANG(DOTS). If there is an exact match
then that element is evaluated and the result returned.
)
EXAMPLES(
centre <- function(x, type) {
switch(type,
        mean=mean(x),
        median=median(x),
        trimmed=mean(x, trim=.1))
}
x <- rcauchy(10)
centre(x, "mean")
centre(x, "median")
centre(x, "trimmed")
)
