-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated function definitions with argument defaults
- Loading branch information
Showing
6 changed files
with
29 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
#' Rescaling datasets | ||
#' | ||
#' @param v A numeric vector | ||
#' @param lower numeric (default:0) | ||
#' @param upper numeric (default:1) | ||
#' | ||
#' @return A new numeric vector, rescaled from the input vector to the range of 0 to 1 | ||
#' @return A new numeric vector, rescaled from the input vector to a range defined by the `lower` and `upper` parameters (default: 0 and 1) | ||
#' | ||
#' @examples | ||
#' rescale(c(1,2,3)) # [1] 0.0 0.5 1.0 | ||
#' rescale(c(1,2,3,4,5)) # [1] 0.00 0.25 0.50 0.75 1.00 | ||
rescale <- function(v) { | ||
(v - min(v)) / (max(v) - min(v)) | ||
#' rescale2(c(1,2,3)) # [1] 0.0 0.5 1.0 | ||
#' rescale2(c(1,2,3,4,5),1,2) # [1] 1.00 1.25 1.50 1.75 2.00 | ||
rescale <- function(v, lower = 0, upper = 1) { | ||
(v - min(v)) / (max(v) - min(v)) * (upper - lower) + lower | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
context("test-center.R") | ||
|
||
test_that("centering works", { | ||
expect_equal(center(c(1,2,3),0), c(-1,0,1)) | ||
test_that("centering works, also relying on default of desired parameter", { | ||
expect_equal(center(c(1,2,3)), c(-1,0,1)) | ||
expect_equal(center(c(1,2,3),1), c(0,1,2)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
context("test-rescale.R") | ||
|
||
test_that("rescaling works", { | ||
test_that("rescaling works, without overwriting the default", { | ||
expect_equal(rescale(1:5), 0.25*(0:4)) | ||
}) | ||
|
||
test_that("rescaling works, without nondefault arguments", { | ||
expect_equal(rescale(1:3,1,2), c(1,1.5,2)) | ||
}) |