-
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?
Conversation
issue quantargo#31- detailed description of a function added
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.
Thanks for your pull request! I've attached a few comments.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
NA
values are subsequently converted to ones and later to zeros through log(1)
. Is this behaviour intentional?
@@ -1,4 +1,6 @@ | |||
#' Meanimputation | |||
#' Calculates mean of a given vector, ignores NA values. |
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.
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")) |
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 statement gives a warning for EVERY negative value in x
.
It would also be sufficient to do a
if(any(x < 0)) {
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 |
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.
And here the zeros are converted again to NA
s (see previous comment).
This part seems could be simplified.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The condition could be expressed more clearly using
if( all(is.na(x)) ) stop("vector contains only NAs")
Codecov Report
@@ Coverage Diff @@
## master #43 +/- ##
========================================
Coverage ? 0.00%
========================================
Files ? 3
Lines ? 19
Branches ? 0
========================================
Hits ? 0
Misses ? 19
Partials ? 0 Continue to review full report at Codecov.
|
I have only one more error, and it concerns PDF version of manual,
and I don't know why