Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions R/winsorize.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ winsorize.data.frame <- function(data, threshold = 0.2, verbose = TRUE, ...) {
#' @rdname winsorize
#' @export
winsorize.numeric <- function(data, threshold = 0.2, verbose = TRUE, ...) {
if (threshold < 0 || threshold > 1) {
if (threshold < 0 || threshold > 0.5) {
if (isTRUE(verbose)) {
warning("'threshold' for winsorization must be a scalar between 0 and 1. Did not winsorize data.", call. = FALSE)
warning("'threshold' for winsorization must be a scalar between 0 and 0.5. Did not winsorize data.", call. = FALSE)
}
return(data)
}
Expand All @@ -64,6 +64,9 @@ winsorize.numeric <- function(data, threshold = 0.2, verbose = TRUE, ...) {
itop <- length(data) - ibot + 1
xbot <- y[ibot]
xtop <- y[itop]
winval <- ifelse(data <= xbot, xbot, data)
ifelse(winval >= xtop, xtop, winval)

winval <- data
winval[winval <= xbot] <- xbot
winval[winval >= xtop] <- xtop
winval
}