From 74118a57239924ea656da78e8d73fb98a830735b Mon Sep 17 00:00:00 2001 From: Nanda Kallugjeri <49677108+nandakallugjeri@users.noreply.github.com> Date: Wed, 1 May 2019 13:14:15 +0200 Subject: [PATCH 1/6] Adding removal of lower outliers. --- R/windsorize.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/windsorize.R b/R/windsorize.R index b4e15e6..b0065ed 100644 --- a/R/windsorize.R +++ b/R/windsorize.R @@ -3,7 +3,7 @@ #' Do some windsorization. #' @export windsorize <- function(x, p = .90) { - q <- quantile(x, p) + q <- quantile(x, probs = c(1-p,p)) x[x >= q] <- q x } From 4234834ac3b8c51d739bef4b22b7f018089a2a10 Mon Sep 17 00:00:00 2001 From: Nanda Kallugjeri <49677108+nandakallugjeri@users.noreply.github.com> Date: Wed, 1 May 2019 13:40:07 +0200 Subject: [PATCH 2/6] Adding error message in case of empty vector or all NA-s vector. --- R/windsorize.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/windsorize.R b/R/windsorize.R index b0065ed..f6ce164 100644 --- a/R/windsorize.R +++ b/R/windsorize.R @@ -3,8 +3,11 @@ #' Do some windsorization. #' @export windsorize <- function(x, p = .90) { - q <- quantile(x, probs = c(1-p,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 } From e8be034b19021a9cdb26e729cde3d57fa92e2ff8 Mon Sep 17 00:00:00 2001 From: Nanda Kallugjeri <49677108+nandakallugjeri@users.noreply.github.com> Date: Wed, 1 May 2019 14:16:30 +0200 Subject: [PATCH 3/6] Adding transform_log function. --- R/transform_log.R | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 R/transform_log.R diff --git a/R/transform_log.R b/R/transform_log.R new file mode 100644 index 0000000..8a17ee6 --- /dev/null +++ b/R/transform_log.R @@ -0,0 +1,10 @@ +#' Log Transform +#' +#' Transform numerical values into their log values. +#' @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 From a91d273a75c26fabe2b3804c0b3c7bf75dd41ec2 Mon Sep 17 00:00:00 2001 From: Nanda Kallugjeri <49677108+nandakallugjeri@users.noreply.github.com> Date: Wed, 1 May 2019 14:22:42 +0200 Subject: [PATCH 4/6] Adding Documentation for Windsorize function. --- R/transform_log.R | 4 ++++ R/windsorize.R | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/R/transform_log.R b/R/transform_log.R index 8a17ee6..a51bf1d 100644 --- a/R/transform_log.R +++ b/R/transform_log.R @@ -1,6 +1,10 @@ #' 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 ) diff --git a/R/windsorize.R b/R/windsorize.R index f6ce164..e6b4331 100644 --- a/R/windsorize.R +++ b/R/windsorize.R @@ -1,7 +1,15 @@ #' 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. +#' +#' @example +#' windsorize(c(1,499,500,501)) #' @export +#' windsorize <- function(x, p = .90) { 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') From 53146f9b5fc59d54459247ca5323c4351ddb664a Mon Sep 17 00:00:00 2001 From: Nanda Kallugjeri <49677108+nandakallugjeri@users.noreply.github.com> Date: Wed, 1 May 2019 14:35:09 +0200 Subject: [PATCH 5/6] Bug fixing Documentation process. --- R/windsorize.R | 3 +-- man/transform_log.Rd | 24 ++++++++++++++++++++++++ man/windsorize.Rd | 11 ++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 man/transform_log.Rd diff --git a/R/windsorize.R b/R/windsorize.R index e6b4331..df10f03 100644 --- a/R/windsorize.R +++ b/R/windsorize.R @@ -1,12 +1,11 @@ #' Windsorize #' -#' #' 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. #' -#' @example +#' @examples #' windsorize(c(1,499,500,501)) #' @export #' 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)) } From e31b333808393def2bd003536f98187585d7695f Mon Sep 17 00:00:00 2001 From: Nanda Kallugjeri <49677108+nandakallugjeri@users.noreply.github.com> Date: Wed, 1 May 2019 14:55:00 +0200 Subject: [PATCH 6/6] Fixing all the Notes and Warning after Run CMD Check. --- DESCRIPTION | 1 - NAMESPACE | 1 + R/meanimpute.R | 4 ++++ man/meanimpute.Rd | 5 ++++- 4 files changed, 9 insertions(+), 2 deletions(-) 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/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} }