winsorize: Winsorize outliers by capping extreme values

View source: R/winsorize.R

winsorizeR Documentation

Winsorize outliers by capping extreme values

Description

Replaces extreme values in selected columns with the specified top and bottom quantile thresholds, rather than deleting them. This is useful for reducing the influence of outliers while preserving sample size.

Usage

winsorize(data, cols = NULL, top = 0.995, bottom = 0.0025,
          group = NULL, verbose = FALSE)

Arguments

data

A data frame, matrix, or numeric vector.

cols

The column indices or names of selected variables. If NULL, all columns are used.

top

The top quantile threshold. Values above this are capped at the threshold.

bottom

The bottom quantile threshold. Values below this are capped at the threshold.

group

Optional grouping column for group-wise winsorization.

verbose

Logical; if TRUE, prints progress message.

Value

A data frame with extreme values capped.

Examples

winsorize(data[1:100, c(1, 4, 17:19)], cols = 3:5)

dataprep documentation built on Oct. 1, 2026, 5:07 p.m.