Main /

Switch

edit SideBar

Switch

Use switch() as a conditional function with multiple conditions.

From R Help:

switch evaluates EXPR and accordingly chooses one of the
further arguments (in ...).
Usage
switch(EXPR, ...)
Arguments
EXPR an expression evaluating to a number or a character string.
... the list of alternatives, given explicitly.

Example:

> x=1
> switch(x,"a","b")
[1] "a"

Or combined with an if to test multiple conditions in one statement:

> x=1
> y="a"
> if(switch(x,"a","b")==y) cat("Match")
Match
Recent Changes (All) | Edit SideBar Page last modified on December 01, 2006, at 10:23 PM Edit Page | Page History
Powered by PmWiki