diff --git a/DESCRIPTION b/DESCRIPTION index 492ae33..8b44a60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,6 +11,5 @@ Encoding: UTF-8 LazyData: true Suggests: testthat, - covr, rmarkdown RoxygenNote: 6.1.1 diff --git a/NAMESPACE b/NAMESPACE index d75f824..1015c5a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1 +1,2 @@ exportPattern("^[[:alpha:]]+") +importFrom("stats", "quantile") \ No newline at end of file diff --git a/R/meanimpute.R b/R/meanimpute.R index cc7cf5e..01b5799 100644 --- a/R/meanimpute.R +++ b/R/meanimpute.R @@ -1,4 +1,8 @@ #' Meanimputation +#' +#' Removes NA-s with the mean value for the vector \code{x} +#' +#' @param x A numeric vector #' @export meanimpute <- function(x) { x[is.na(x)] <- mean(x, na.rm = TRUE) diff --git a/R/transform_log.R b/R/transform_log.R new file mode 100644 index 0000000..a51bf1d --- /dev/null +++ b/R/transform_log.R @@ -0,0 +1,14 @@ +#' Log Transform +#' +#' Transform numerical values into their log values. +#' @param x A numeric vector. +#' @return The log values of \code{x}. +#' @examples +#' transform_log(exp(rnorm(7))) +#' @export + +transform_log<- function( x ) +{ + if( !is.numeric(x)) stop('Non numeric values found in passed paramenter.') + log(x ) +} \ No newline at end of file diff --git a/R/windsorize.R b/R/windsorize.R index b4e15e6..df10f03 100644 --- a/R/windsorize.R +++ b/R/windsorize.R @@ -1,10 +1,20 @@ #' Windsorize #' -#' Do some windsorization. +#' Replacing values of vector \code{x} greater or smaller then \code{q} quantile values. +#' +#' @param x A numerical vector. +#' @param p Quantile value for outliers removal. +#' +#' @examples +#' windsorize(c(1,499,500,501)) #' @export +#' windsorize <- function(x, p = .90) { - q <- quantile(x, p) - x[x >= q] <- q + if(length(x) == 0) stop('Empty vector passed as an argument.') + if( sum(is.na(x)) == length(x) ) stop('A vector of NA-s passed as an argument') + q <- quantile(x, probs = c(1-p,p), na.rm = TRUE) + x[x >= q[2] ] <- q[2] + x[x <= q[1] ] <- q[1] x } diff --git a/man/meanimpute.Rd b/man/meanimpute.Rd index 8139e8f..a2a189e 100644 --- a/man/meanimpute.Rd +++ b/man/meanimpute.Rd @@ -6,6 +6,9 @@ \usage{ meanimpute(x) } +\arguments{ +\item{x}{A numeric vector} +} \description{ -Meanimputation +Removes NA-s with the mean value for the vector \code{x} } diff --git a/man/transform_log.Rd b/man/transform_log.Rd new file mode 100644 index 0000000..c6c593f --- /dev/null +++ b/man/transform_log.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/transform_log.R +\name{transform_log} +\alias{transform_log} +\title{Log Transform + +Transform numerical values into their log values.} +\usage{ +transform_log(x) +} +\arguments{ +\item{x}{A numeric vector.} +} +\value{ +The log values of \code{x}. +} +\description{ +Log Transform + +Transform numerical values into their log values. +} +\examples{ +transform_log(exp(rnorm(7))) +} diff --git a/man/windsorize.Rd b/man/windsorize.Rd index 832c3cb..e71bd1e 100644 --- a/man/windsorize.Rd +++ b/man/windsorize.Rd @@ -6,6 +6,15 @@ \usage{ windsorize(x, p = 0.9) } +\arguments{ +\item{x}{A numerical vector.} + +\item{p}{Quantile value for outliers removal.} +} \description{ -Do some windsorization. +Replacing values of vector \code{x} greater or smaller then \code{q} quantile values. +} +\examples{ + +windsorize(c(1,499,500,501)) }