diff --git a/NAMESPACE b/NAMESPACE index d75f824..c1a7cea 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1 +1,2 @@ exportPattern("^[[:alpha:]]+") +importFrom("stats", "quantile") diff --git a/R/meanimpute.R b/R/meanimpute.R index cc7cf5e..2fc9634 100644 --- a/R/meanimpute.R +++ b/R/meanimpute.R @@ -1,6 +1,5 @@ #' Meanimputation +#' @param x A vector #' @export meanimpute <- function(x) { - x[is.na(x)] <- mean(x, na.rm = TRUE) - x -} + x[is.na(x)] <- mean(x, na.rm = TRUE) \ No newline at end of file diff --git a/R/transformlog.R b/R/transformlog.R new file mode 100644 index 0000000..f0018ac --- /dev/null +++ b/R/transformlog.R @@ -0,0 +1,8 @@ +transform_log<- function(x){ + if (x<0) stop("Negative input not allowed") + if (x==0) stop("Input 0 not allowed") + if (!is.numeric(x)) stop("Not numeric input not allowed") + if (is.null(x)) stop("NULL input not allowed") + + log(x) +} diff --git a/R/windsorize.R b/R/windsorize.R index b4e15e6..b961541 100644 --- a/R/windsorize.R +++ b/R/windsorize.R @@ -1,10 +1,20 @@ #' Windsorize #' #' Do some windsorization. +#' @param x A numerical vector. +#' @param p Quantile value for outliers removal +#' @examples +#' windsorize(c(5,10,15,50)) #' @export windsorize <- function(x, p = .90) { - q <- quantile(x, p) - x[x >= q] <- q + if (length(x) == 0) + { stop("Not allowed the use of an empty vector!")} + if (all(is.na(x))) + { stop("Not allowed the use of a vector containing only NA!")} + + q <- quantile(x, probs=c(1-p,p) , na.rm = TRUE) + x[x >= q[2] ] <- q[2] + x[x <= q[1] ] <- q[1] x }