From e25d36c760f78c54d8b31c438b475da848166b5c Mon Sep 17 00:00:00 2001 From: Filip Smolik Date: Sun, 5 May 2019 11:36:13 +0200 Subject: [PATCH] #22 - function for log-transformation is added. --- R/transform_log.R | 20 ++++++++++++++++++++ 1 file changed, 20 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..ba11c66 --- /dev/null +++ b/R/transform_log.R @@ -0,0 +1,20 @@ +#' transform_log +#' +#' log-transformation of a numeric vector. For details about log-transformation please see you basic school math textbook. +#' @param x a numeric vector +#' @return log-transformed vector \code{x} +#' @examples +#' example_vector=c(1,2,3,4,5,6,7,8,9,10) +#' transform_log(example_vector) +#' @export + +transform_log <- function(x){ + + if( is.null(x) ) stop("Input vector is not allowed to be NULL.") + if( any(is.na(x)) ) stop("There is at least one NA value in input vector.") + if( any(x <= 0) ) stop("There is at least one negative value.") + if( any(is.numeric(x) == FALSE) ) stop("There is at least one non-numeric value.") + y<-log(x) + return(y) + +} \ No newline at end of file