Learn R Programming

quickOutlier (version 0.1.0)

detect_outliers: Detect Anomalies in a Data Frame

Description

This function identifies rows containing outliers in a specific numeric column. It supports two methods:

  • zscore: Based on the standard deviation (statistical approach). Best for normal distributions.

  • iqr: Based on the Interquartile Range (robust approach). Best for data with skewness or extreme outliers.

Usage

detect_outliers(data, column, method = "zscore", threshold = 3)

Value

A data frame containing only the rows considered outliers, with an additional column displaying the calculated score or bounds.

Arguments

data

A data frame containing the data to analyze.

column

A string specifying the name of the numeric column to analyze.

method

A character string. "zscore" or "iqr". Defaults to "zscore".

threshold

A numeric value. The cutoff limit. Defaults to 3 for "zscore" and 1.5 for "iqr".

Examples

Run this code
# Example with a clear outlier
df <- data.frame(
  id = 1:6,
  value = c(10, 12, 11, 10, 500, 11)
)

# Detect using IQR (Robust)
detect_outliers(df, column = "value", method = "iqr")

# Detect using Z-Score
detect_outliers(df, column = "value", method = "zscore")

Run the code above in your browser using DataLab