This repository has been archived by the owner on Jan 30, 2025. It is now read-only.
-
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.
- Loading branch information
1 parent
7044262
commit b69d2d2
Showing
5 changed files
with
58 additions
and
3 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,16 +1,33 @@ | ||
# DATA TRANSFORMATION | ||
NULL | ||
|
||
#' Rescale Continuous Vector | ||
#' Rescale Continuous Vector (minimum, maximum) | ||
#' | ||
#' Rescales continuous vector to have specified minimum and maximum. | ||
#' @param x A [`numeric`] vector. | ||
#' @param to A length-two [`numeric`] vector specifying the output range. | ||
#' @param from A length-two [`numeric`] vector specifying the input range. | ||
#' @note For internal use only. | ||
#' @return A [`numeric`] vector. | ||
#' @note For internal use only. | ||
#' @family data transformation tools | ||
#' @export | ||
scale_range <- function(x, to = c(0, 1), from = range(x, finite = TRUE)) { | ||
(x - from[1L]) / diff(from) * diff(to) + to[1L] | ||
} | ||
|
||
#' Rescale Continuous Vector (minimum, midpoint, maximum) | ||
#' | ||
#' Rescales continuous vector to have specified minimum, midpoint and maximum. | ||
#' @param x A [`numeric`] vector. | ||
#' @param to A length-two [`numeric`] vector specifying the output range. | ||
#' @param from A length-two [`numeric`] vector specifying the input range. | ||
#' @param midpoint A length-one [`numeric`] vector specifying the mid-point of input | ||
#' range. | ||
#' @return A [`numeric`] vector. | ||
#' @note For internal use only. | ||
#' @family data transformation tools | ||
#' @export | ||
scale_midpoint <- function(x, to = c(0, 1), from = range(x, finite = TRUE), midpoint = 0) { | ||
extent <- 2 * max(abs(from - midpoint)) | ||
(x - midpoint) / extent * diff(to) + mean(to) | ||
} |
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
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.