-
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
Quatargo exercise - modify existing package - Zoltan #8
base: master
Are you sure you want to change the base?
Changes from all commits
5782aa0
92dc538
b560f90
d812108
8f2c7b1
04a8d03
de64e38
ed0e383
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#' Meanimputation | ||
#' @param x A vector. | ||
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. Longer description missing. |
||
#' | ||
#' @export | ||
meanimpute <- function(x) { | ||
x[is.na(x)] <- mean(x, na.rm = TRUE) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#' Transform_log | ||
#' | ||
#' Log transformation. | ||
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 could be longer here. |
||
#' | ||
#' @param x A vector. | ||
#' | ||
#' @examples | ||
#' transform_log(exp(rnorm(2))) | ||
#' | ||
#' @export | ||
|
||
transform_log <- function(x) { | ||
if (any(x<0)) {stop("input can't be negative")} | ||
x <- log(x) | ||
x | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
#' Windsorize | ||
#' | ||
#' Do some windsorization. | ||
#' | ||
#' Winsorizing or winsorization is the transformation of statistics by limiting | ||
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. Nice description! Just missing how input parameter |
||
#' extreme values in the statistical data to reduce the effect of possibly | ||
#' spurious outliers. | ||
#' | ||
#' @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(all(is.na(x))) {stop("argument should not be a vector containing only NA-s or NULL-s")} | ||
q_up <- quantile(x, 0.5 + p / 2 ) | ||
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. Try to consider the following situations:
|
||
q_down <- quantile(x, 0.5 - p / 2 ) | ||
x[x >= q_up] <- q_up | ||
x[x <= q_down] <- q_down | ||
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,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") | ||
}) |
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") | ||
}) |
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.
Why haven't you used the package roxygen2 to generate the NAMESPACE file?