Learn R Programming

quickOutlier (version 0.1.0)

treat_outliers: Treat Outliers (Winsorization/Capping)

Description

Instead of removing outliers, this function replaces extreme values with the calculated upper and lower boundaries (caps). This technique is often called "Winsorization".

Usage

treat_outliers(data, column, method = "iqr", threshold = 1.5)

Value

A data frame with the modified column values.

Arguments

data

A data frame.

column

The numeric column to treat.

method

"iqr" or "zscore".

threshold

Numeric (1.5 for IQR, 3 for zscore).

Examples

Run this code
# Example: 100 is an outlier
df <- data.frame(val = c(1, 2, 3, 2, 1, 100))

# The 100 will be replaced by the maximum allowed IQR value
clean_df <- treat_outliers(df, "val", method = "iqr")
print(clean_df$val)

Run the code above in your browser using DataLab