switch2 | R Documentation |
switch
which accepts a vector of strings.
switch2(x, ..., nomatch = NA)
x |
a vector of character strings |
... |
a list of alternatives; see |
nomatch |
the value returned when no matching case is given |
switch('a', a = 10, b = 2:0, c = 3, d = 1.5, e = mean)
switch('b', a = 10, b = 2:0, c = 3, d = 1.5, e = mean)
# switch(c('a', 'b'), a = 10, b = 2:0, c = 3, d = 1.5, e = mean) ## error
switch2(c('d', 'a'), a = 10, b = 2:0, c = 3, d = 1.5, e = mean)
switch2(c('b', 'a'), a = 10, b = 2:0, c = 3, d = 1.5, e = mean)
switch2(c('b', 'a', 'e'), a = 10, b = 2:0, c = 3, d = 1.5, e = mean)
## no matching expressions
switch2(c('a', 'b', 'e', 'f'), a = 1, b = 2)
switch2(c('a', 'b', 'e', 'f'), a = 1, b = 2, nomatch = 'other')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.