find_outliers: Detect Statistical Outliers Using IQR Method

View source: R/find_outliers.R

find_outliersR Documentation

Detect Statistical Outliers Using IQR Method

Description

Identifies statistical outliers in a numeric variable using the Interquartile Range (IQR) method. Provides detailed diagnostics about the outlier detection process.

Usage

find_outliers(data, variable_name, verbose = TRUE)

Arguments

data

Data frame containing the variable to analyze.

variable_name

Unquoted name of the numeric variable to check for outliers.

verbose

Logical. If TRUE, prints diagnostic information about quartiles, fences, and number of outliers found. Default is TRUE.

Details

The function uses the standard IQR method for outlier detection:

  • Calculates Q1 (25th percentile) and Q3 (75th percentile)

  • Computes IQR = Q3 - Q1

  • Defines outliers as values outside (Q1 - 1.5IQR, Q3 + 1.5IQR)

Value

If outliers are found:

  • Data frame containing rows with outlier values

  • Prints diagnostic information about quartiles and fences

If no outliers:

  • Returns NULL

  • Prints confirmation message

Diagnostic Output

  • Variable name

  • Q1 and Q3 values

  • IQR value

  • Upper and lower fence values

  • Number of outliers found

Examples

data(mtcars)
find_outliers(mtcars, mpg)
find_outliers(mtcars, wt, verbose = FALSE)


qtkit documentation built on April 4, 2025, 4:47 a.m.