Created
March 22, 2016 22:29
-
-
Save bfatemi/15404b2432ef5f30330a to your computer and use it in GitHub Desktop.
Example of match.arg()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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