From 10961870aa1fc54700af3999e44179b460c54c1b Mon Sep 17 00:00:00 2001 From: MarkoBarzic Date: Mon, 6 May 2019 22:17:52 +0200 Subject: [PATCH 1/7] issue #30- adding importFrom("stats","quantile") to NAMESPACE --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index d75f824..c1a7cea 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1 +1,2 @@ exportPattern("^[[:alpha:]]+") +importFrom("stats", "quantile") From 9514ba40b4ce4cca8df5703b0c8c25f3298b3024 Mon Sep 17 00:00:00 2001 From: MarkoBarzic Date: Mon, 6 May 2019 22:27:25 +0200 Subject: [PATCH 2/7] issue #30- function argument documented, issue #31- detailed description of a function added --- R/meanimpute.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/meanimpute.R b/R/meanimpute.R index cc7cf5e..f7f79e5 100644 --- a/R/meanimpute.R +++ b/R/meanimpute.R @@ -1,4 +1,5 @@ #' Meanimputation +#' @param x A vector #' @export meanimpute <- function(x) { x[is.na(x)] <- mean(x, na.rm = TRUE) From cd2ebaac92bbafd09bcc53cbd353d5ce1db71e92 Mon Sep 17 00:00:00 2001 From: MarkoBarzic Date: Mon, 6 May 2019 22:28:53 +0200 Subject: [PATCH 3/7] issue #32- added function Log transform --- R/transform_log.R | 18 ++++++++++++++++++ 1 file changed, 18 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..c9045b9 --- /dev/null +++ b/R/transform_log.R @@ -0,0 +1,18 @@ +#' transform_log +#' Transform numerical values into their log values +#' @param x A vector +#' @return logarithm of x +#' @examples +#' transform_log(c(NA,0,-1,exp(2))) +#'@export +transform_log<-function(x){ + if(!is.numeric(x))stop("function is expecting only numeric values") + x_nan<-is.na(x) + x[x_nan]<-1 + ifelse(x<0,"OK", warning("input vector contains negative values, turned into NA")) + y<-log(x[x>=0]) + x[x>=0]<-y + x[x<0]<-NA + x[x_nan]<-NA + x +} \ No newline at end of file From d258cdc6012921539be7da37f63715c7cd4b69a4 Mon Sep 17 00:00:00 2001 From: MarkoBarzic Date: Mon, 6 May 2019 22:48:39 +0200 Subject: [PATCH 4/7] issues #28-#31- corrected function, updated documentation --- R/windsorize.R | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/R/windsorize.R b/R/windsorize.R index b4e15e6..85044f8 100644 --- a/R/windsorize.R +++ b/R/windsorize.R @@ -1,10 +1,23 @@ #' Windsorize #' -#' Do some windsorization. +#' +#' Transform all outliner data to +#' (1-p)/2 percentile value for lower outliers and +#' (1+p)/2 for higher outliers. +#' +#' @param x A vector. +#' @param p A quantile. +#' @return inuput vector x with trimmed outliers by (1-p) percentile. +#' @examples +#' windsorize(rnorm(100,0,1)) #' @export windsorize <- function(x, p = .90) { - q <- quantile(x, p) - x[x >= q] <- q + if(is.null(x))stop("vector is empty") + y<-x[!is.na(x)] + if(length(y)==0)stop("vector contains only NAs") + q_max <- quantile(y, (1+p)/2) + q_min<- quantile(y,(1-p)/2) + x[x >= q_max] <- q_max + x[x<= q_min]<-q_min x -} - +} \ No newline at end of file From e1239727fb82af4859a8be0ccf92c024e20daaff Mon Sep 17 00:00:00 2001 From: MarkoBarzic Date: Mon, 6 May 2019 22:51:07 +0200 Subject: [PATCH 5/7] #31-added description of the function --- R/meanimpute.R | 1 + man/meanimpute.Rd | 3 +++ 2 files changed, 4 insertions(+) diff --git a/R/meanimpute.R b/R/meanimpute.R index f7f79e5..9023102 100644 --- a/R/meanimpute.R +++ b/R/meanimpute.R @@ -1,4 +1,5 @@ #' Meanimputation +#' Calculates mean of a given vector, ignores NA values. #' @param x A vector #' @export meanimpute <- function(x) { diff --git a/man/meanimpute.Rd b/man/meanimpute.Rd index 8139e8f..77f2fbc 100644 --- a/man/meanimpute.Rd +++ b/man/meanimpute.Rd @@ -6,6 +6,9 @@ \usage{ meanimpute(x) } +\arguments{ +\item{x}{A vector} +} \description{ Meanimputation } From 37de5d53053862404501f67077a979e0eb5c7212 Mon Sep 17 00:00:00 2001 From: MarkoBarzic Date: Mon, 6 May 2019 22:52:07 +0200 Subject: [PATCH 6/7] #31-added explanations for function windsorize --- man/windsorize.Rd | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/man/windsorize.Rd b/man/windsorize.Rd index 832c3cb..dcabd36 100644 --- a/man/windsorize.Rd +++ b/man/windsorize.Rd @@ -6,6 +6,19 @@ \usage{ windsorize(x, p = 0.9) } +\arguments{ +\item{x}{A vector.} + +\item{p}{A quantile.} +} +\value{ +inuput vector x with trimmed outliers by (1-p) percentile. +} \description{ -Do some windsorization. +Transform all outliner data to +(1-p)/2 percentile value for lower outliers and +(1+p)/2 for higher outliers. +} +\examples{ +windsorize(rnorm(100,0,1)) } From 3706cdc513a25c4e1dd99e1c20e1e2852142777a Mon Sep 17 00:00:00 2001 From: MarkoBarzic Date: Mon, 6 May 2019 22:54:40 +0200 Subject: [PATCH 7/7] #32 #31- added explanation for function Log transform --- man/transform_log.Rd | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 man/transform_log.Rd diff --git a/man/transform_log.Rd b/man/transform_log.Rd new file mode 100644 index 0000000..c42f726 --- /dev/null +++ b/man/transform_log.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/transform_log.R +\name{transform_log} +\alias{transform_log} +\title{transform_log +Transform numerical values into their log values} +\usage{ +transform_log(x) +} +\arguments{ +\item{x}{A vector} +} +\value{ +logarithm of x +} +\description{ +transform_log +Transform numerical values into their log values +} +\examples{ +transform_log(c(NA,0,-1,exp(2))) +}