-
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
Implemented Features #1 #3 #5 #6 #33
base: master
Are you sure you want to change the base?
Changes from all commits
5b39d7d
23a38fe
fe77e6a
d80308d
8352e55
8a551e4
c9d0d26
0723c6b
ed28c49
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,5 @@ | ||
exportPattern("^[[:alpha:]]+") | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(meanimpute) | ||
export(transform_log) | ||
export(windsorize) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#' Log transforms data. | ||
#' | ||
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. Again, a short description what the function is actually doing. |
||
#' @param x A numeric vector containing the data | ||
#' @return A numeric vector whose entries are the logarithms of the input. | ||
#' @examples | ||
#' log(1:5) | ||
#' @export | ||
transform_log<-function(x){ | ||
if(length(x)==0){ | ||
stop("x must have positive length") | ||
}else if(sum(x<=0)>0){ | ||
stop("x must not contain non-positive values") | ||
}else if(sum(is.na(x))>0){ | ||
stop("x must not contain any 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. Why are no |
||
} | ||
log(x) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
#' Windsorize | ||
#' Windsorizes data. | ||
#' | ||
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. Description missing |
||
#' Do some windsorization. | ||
#' @param x A numeric vector containing the data. | ||
#' @param p A numeric value denoting the a probability | ||
#' @return A numeric vector containing the windsorized data, i.e. extreme values are replaced by the quantiles derived from \code{p}. | ||
#' @examples | ||
#' windsorize(c(92 , 19 , 101 , 58 , 1053 , 91 , 26 , 78 , 10 , 13 , -40 , 101 , 86 , 85 , 15 , 89 , 89 , 28 , -5 , 41)) | ||
#' @export | ||
windsorize <- function(x, p = .90) { | ||
q <- quantile(x, p) | ||
x[x >= q] <- q | ||
if(length(x)==0){ | ||
stop("x must be of positive length") | ||
}else if(sum(is.na(x))>0){ | ||
stop("x must not contain any 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. Does the function have to return an error if the vector contains |
||
} | ||
q <- quantile(x, 0.5 * ( 1 + p * c(-1,1) ) ) | ||
x[x >= q[2] ] <- q[2] | ||
x[x <= q[1] ] <- q[1] | ||
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library(testthat) | ||
library(datacleaner) | ||
|
||
test_check("datacleaner") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test_that("windsorize works", { | ||
expect_equal(windsorize(3:10), c(3.35,4.00,5.00,6.00,7.00,8.00,9.00,9.65)) | ||
}) |
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.
A longer function description would be nice here.