winsorize: 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)
Value
A data frame with extreme values capped.
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.