| outlier | R Documentation |
Return outliers in a vector
outlier(x = NULL, iqr = 1.5, na.rm = TRUE, type = 7, unique_outliers = FALSE)
x |
a numeric vector |
iqr |
a nonnegative constant by which interquartile range (IQR)
will be multiplied to build a "fence," outside which observations
will be considered outliers. For example, if |
na.rm |
logical. |
type |
|
unique_outliers |
logical. If |
the output will be a numeric vector with outliers removed.
# Example 1 outlier(c(1:10, 100)) # The steps below show how the outlier, 100, was obtained # v1 is the vector of interest v1 <- c(1:10, 100) # quantile stats::quantile(v1) # first and third quartiles q1 <- stats::quantile(v1, 0.25) q3 <- stats::quantile(v1, 0.75) # interquartile range interquartile_range <- unname(q3 - q1) # fence, using the default 1.5 as the factor to multiply the IQR cutoff_low <- unname(q1 - 1.5 * interquartile_range) cutoff_high <- unname(q3 + 1.5 * interquartile_range) v1[v1 < cutoff_low | v1 > cutoff_high]