winsorize: Winsorize vector

View source: R/winsorize.R

winsorizeR Documentation

Winsorize vector

Description

Replace extreme values by absolute or quantile threshold

Usage

winsorize(
  x,
  lo = NULL,
  hi = NULL,
  prob.lo = 0.025,
  prob.hi = 0.975,
  quantile.type = 7,
  verbose = TRUE
)

Arguments

x

Numeric vector: Input data

lo

Numeric: If not NULL, replace any values in x lower than this with this. Default = NULL

hi

Numeric: If not NULL, replace any values in x higher than this with this.

prob.lo

Numeric (0, 1): If not NULL and lo = NULL, find sample quantile that corresponds to this probability and set as lo.

prob.hi

Numeric (0, 1): If not NULL and hi = NULL, find sample quantile that corresponds to this probability and set as hi.

quantile.type

Integer: passed to stats::quantile

verbose

Logical: If TRUE, print messages to console.

Details

If both lo and prob.lo or both hi and prob.hi are NULL, cut-off is set to min(x) and max(x) respectively, i.e. no values are changed

Author(s)

E.D. Gennatas

Examples

# Winsorize a normally distributed variable
x <- rnorm(500)
xw <- winsorize(x)
# Winsorize an exponentially distributed variable only on 
# the top 5% highest values
x <- rexp(500)
xw <- winsorize(x, prob.lo = NULL, prob.hi = .95)

egenn/rtemis documentation built on April 24, 2024, 6:58 p.m.