R - match.arg()

15 Oct 2017

match.arg(arg, choices, several.ok = FALSE) matches arg against a table of candidate values as specified by choices, where NULL means to take the first one.

In the example below:

center <- function(x, type = c("mean", "median", "trimmed")) {
  type <- match.arg(type)
  switch(type,
         mean = mean(x),
         median = median(x),
         trimmed = mean(x, trim = .1))
}

[ R  function  ]