Skip to contents

unique_outliers() returns the unique outliers of a numeric vector based on the interquartile range (IQR).

This function first removes duplicated values from the input vector x to ensure that outlier detection is based on unique values. It then calculates the first (Q1) and third (Q3) quartiles, as well as the IQR. Outliers are defined as values that fall below Q1 - n_iqr * IQR or above Q3 + n_iqr * IQR, where n_iqr is a user-defined multiplier (default is 1.5).

Usage

unique_outliers(x, n_iqr = 1.5)

Arguments

x

An numeric vector with at least 4 values.

n_iqr

(optional) A number specifying the multiplier of the interquartile range (IQR) to define outliers (default: 1.5).

Value

A numeric vector with the outliers of x.

Examples

c(1:10) |> unique_outliers()
#> integer(0)
#> integer(0) # Expected

c(1:10, 100L) |> unique_outliers()
#> [1] 100
#> [1] 100 # Expected

c(1:10, 100L) |> unique_outliers(n_iqr = 1000)
#> integer(0)
#> integer(0) # Expected