Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ License: GPL-3
Encoding: UTF-8
LazyData: true
Suggests:
testthat,
testthat (>= 2.1.0),
covr,
rmarkdown
RoxygenNote: 6.1.1
6 changes: 5 additions & 1 deletion NAMESPACE
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)
5 changes: 5 additions & 0 deletions R/meanimpute.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#' Meanimputation
#'
Copy link
Member

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.

#' @param x A numeric vector containing the data
#' @return the input vector with its NA values replaced by the mean
#' @examples
#' log(1:5)
#' @export
meanimpute <- function(x) {
x[is.na(x)] <- mean(x, na.rm = TRUE)
Expand Down
17 changes: 17 additions & 0 deletions R/transform_log.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' Log transforms data.
#'
Copy link
Member

Choose a reason for hiding this comment

The 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are no NA's allowed during the log-transform?

}
log(x)
}
18 changes: 14 additions & 4 deletions R/windsorize.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#' Windsorize
#' Windsorizes data.
#'
Copy link
Member

Choose a reason for hiding this comment

The 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the function have to return an error if the vector contains NA's?
The specifications says it has to return an error if the vector contains ONLY NA's.
What could be the workaround?

}
q <- quantile(x, 0.5 * ( 1 + p * c(-1,1) ) )
x[x >= q[2] ] <- q[2]
x[x <= q[1] ] <- q[1]
x
}

9 changes: 9 additions & 0 deletions man/meanimpute.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/transform_log.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions man/windsorize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(datacleaner)

test_check("datacleaner")
3 changes: 3 additions & 0 deletions tests/testthat/test-windsorize.R
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))
})