Skip to content

Instantly share code, notes, and snippets.

@TrevorMcCormick
Created May 12, 2016 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrevorMcCormick/1fec629451d96222aa5166f128e528d9 to your computer and use it in GitHub Desktop.
Save TrevorMcCormick/1fec629451d96222aa5166f128e528d9 to your computer and use it in GitHub Desktop.
R Function to remove outliers
remove_outliers <- function(x, na.rm = TRUE, ...) {
qnt <- quantile(x, probs=c(.25, .75), na.rm = na.rm, ...)
H <- 1.5 * IQR(x, na.rm = na.rm)
y <- x
y[x < (qnt[1] - H)] <- NA
y[x > (qnt[2] + H)] <- NA
y
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment