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

Add Contributing.md #45

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
exportPattern("^[[:alpha:]]+")
importFrom("stats", "quantile")
2 changes: 2 additions & 0 deletions R/meanimpute.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#' Meanimputation
#' @param x A vector.
#'
#' @export
meanimpute <- function(x) {
x[is.na(x)] <- mean(x, na.rm = TRUE)
Expand Down
16 changes: 16 additions & 0 deletions R/transform_log.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Transform_log
#'
#' Log transformation.
#'
#' @param x A vector.
#'
#' @examples
#' transform_log(exp(rnorm(2)))
#'
#' @export

transform_log <- function(x) {
if (any(x<0)) {stop("log values must be positive")}
x <- log(x)
x
}
21 changes: 18 additions & 3 deletions R/windsorize.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#' Windsorize
#'
#' Do some windsorization.
#' Winsorizing or winsorization is the transformation of statistics by limiting
#' extreme values to reduce the effect of
#' spurious outliers in statistical data.
#'
#' @param x A vector.
#' @param p A quantile.
#'
#' @examples
#' windsorize(rnorm(5))
#'
#' @export
windsorize <- function(x, p = .90) {
q <- quantile(x, p)
x[x >= q] <- q
if (is.null(x)) {
stop("nul vector")}
if(is.na(x)){
stop("NA vector")}
q_low <- quantile(x, 0.5-p/2)
q_high <- quantile(x, 0.5+p/2)
x[x >= q_high] <- q_high
x[x <= q_low] <- q_low
x
}

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

test_check("datacleaner")


5 changes: 5 additions & 0 deletions tests/testthat/test_transform_log.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
context("No negative values")
library(datacleaner)
test_that("There are no negative values in input", {
expect_error(transform_log(c(1,2,-1)), "input can't be negative")
})
6 changes: 6 additions & 0 deletions tests/testthat/test_windsorize.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
context("NA and null values")
library(datacleaner)
test_that("NA and null values produce error message", {
expect_error(windsorize(NA), "argument should not be a vector containing only NA-s or NULL-s")
expect_error(windsorize(NULL), "argument should not be a vector containing only NA-s or NULL-s")
})