winsor {quest}R Documentation

Winsorize a Numeric Vector

Description

winsor winsorizes a numeric vector by recoding extreme values as a user-identified boundary value, which is defined by z-score units. The to.na argument provides the option of recoding the extreme values as missing.

Usage

winsor(x, z.min = -3, z.max = 3, rtn.int = FALSE, to.na = FALSE)

Arguments

x

numeric vector

z.min

numeric vector of length 1 specifying the lower boundary value in z-score units.

z.max

numeric vector of length 1 specifying the upper boundary value in z-score units.

rtn.int

logical vector of length 1 specifying whether the recoded values should be rounded to the nearest integer. This can be useful when working with count data and decimal values are impossible.

to.na

logical vector of length 1 specifying whether the extreme values should be recoded to NA rather than winsorized to the boundary values.

Details

Note, the psych package also has a function called winsor, which offers the option to winsorize a numeric vector by quantiles rather than z-scores. If you have both the quest package and the psych package attached in your current R session (e.g., using library), depending on which package you attached first, R might default to using the winsor function in either the quest package or the psych package. One way to deal with this issue is to explicitly call which package you want to use the winsor package from. You can do this using the :: function in base R where the package name comes before the :: and the function names comes after it (e.g., quest::winsor).

Value

numeric vector of the same length as x with extreme values recoded as either the boundary values or NA.

See Also

winsors winsor # psych package

Examples


# winsorize
table(quakes$"stations")
new <- winsor(quakes$"stations")
table(new)

# recode as NA
vecNA(quakes$"stations")
new <- winsor(quakes$"stations", to.na = TRUE)
vecNA(new)

# rtn.int = TRUE
winsor(x = cars[[1]], z.min = -2, z.max = 2, rtn.int = FALSE)
winsor(x = cars[[1]], z.min = -2, z.max = 2, rtn.int = TRUE)

[Package quest version 0.2.0 Index]