Learn R Programming

GimmeMyStats (version 1.0.0)

identify_outliers: Identifies outliers in a numeric vector

Description

Detects outliers using methods like IQR, percentiles, Hampel, MAD, or SD.

Usage

identify_outliers(
  x,
  probabilities = c(0.25, 0.75),
  method = "iqr",
  weight = 1.5,
  replace = FALSE
)

Value

A numeric vector whose content depends on the value of replace:

replace = FALSE

A numeric vector containing only the detected outlier values. The vector is named with the original indices or names of x.

replace = TRUE

A numeric vector of the same length as x, where detected outliers are replaced by NA.

Arguments

x

Vector containing numerical values.

probabilities

Numeric vector specifying probabilities for percentiles.

method

Character specifying the method: iqr, percentiles, hampel, mad, or sd.

weight

Double specifying the multiplier for the detection threshold.

replace

Logical specifying whether to replace outliers with NA.

Examples

Run this code
x <- rnorm(100)
identify_outliers(x, method = "iqr")
identify_outliers(x, method = "percentiles", probabilities = c(0.1, 0.9))
identify_outliers(x, method = "sd", weight = 3)
identify_outliers(x, method = "mad", replace = TRUE)

Run the code above in your browser using DataLab