R/util_tukey.R

Defines functions util_tukey

Documented in util_tukey

#' Utility function Tukey outlier rule
#'
#' This function calculates outliers according to the rule of Tukey.
#'
#' @param x [numeric] data to check for outliers
#'
#' @return binary vector
#'
#' @importFrom stats quantile IQR
util_tukey <- function(x) {
  xq1 <- as.numeric(quantile(x, na.rm = TRUE)[2])
  xiqr <- IQR(x, na.rm = TRUE)
  xq3 <- as.numeric(quantile(x, na.rm = TRUE)[4])
  lth <- xq1 - 1.5 * xiqr
  uth <- xq3 + 1.5 * xiqr
  xbin <- ifelse(x < lth | x > uth, 1, 0)
  return(xbin)
}

Try the dataquieR package in your browser

Any scripts or data that you put into this service are public.

dataquieR documentation built on July 26, 2023, 6:10 p.m.