Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more winsorizing options? #47

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
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
}