-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update of dataclean #43
base: master
Are you sure you want to change the base?
Changes from all commits
1096187
9514ba4
cd2ebaa
d258cdc
e123972
37de5d5
3706cdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
exportPattern("^[[:alpha:]]+") | ||
importFrom("stats", "quantile") |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ifelse(x<0,"OK", warning("input vector contains negative values, turned into NA")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This statement gives a warning for EVERY negative value in
|
||
y<-log(x[x>=0]) | ||
x[x>=0]<-y | ||
x[x<0]<-NA | ||
x[x_nan]<-NA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here the zeros are converted again to |
||
x | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition could be expressed more clearly using
|
||
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 | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function actually replaces all NA values with the mean of a given vector.