From 9602ad8c7a37659c7061069fe765db75f9590548 Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Tue, 4 Jan 2022 09:54:30 +0200 Subject: [PATCH] threshold max is 0.5 --- DESCRIPTION | 2 +- R/winsorize.R | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9e41b368e..c41e38995 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: datawizard Title: Easy Data Wrangling -Version: 0.2.2 +Version: 0.2.2.001 Authors@R: c( person("Dominique", "Makowski", , "dom.makowski@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-5375-9967", Twitter = "@Dom_Makowski")), diff --git a/R/winsorize.R b/R/winsorize.R index 76b421d25..70a3919af 100644 --- a/R/winsorize.R +++ b/R/winsorize.R @@ -49,9 +49,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) } @@ -62,6 +62,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 }