Skip to content

Commit

Permalink
issue quantargo#32- added function Log transform
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkoBarzic committed May 6, 2019
1 parent 9514ba4 commit cd2ebaa
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions R/transform_log.R
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit cd2ebaa

Please sign in to comment.