Skip to content

Instantly share code, notes, and snippets.

@bfatemi
Created March 22, 2016 22:29
Show Gist options
  • Save bfatemi/15404b2432ef5f30330a to your computer and use it in GitHub Desktop.
Save bfatemi/15404b2432ef5f30330a to your computer and use it in GitHub Desktop.
Example of match.arg()
require(stats)
## Extends the example for 'switch'
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))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment