Description Usage Arguments Value Examples
View source: R/general_rescale.R
Rescale a numeric vector with the option to make signed (-1, 1, or 0) and retain zero as neutral.
1 2 3 4 5 6 7 8 9 | general_rescale(
x,
lower = -1,
upper = 1,
mute = NULL,
keep.zero = lower < 0,
sign = FALSE,
...
)
|
x |
A numeric vector. |
lower |
An upper limit to rescale to. |
upper |
A lower limit to rescale to. |
mute |
A positive value greater than 1 to lower the extremes and pull the fractions up. This becomes the denominator in a power to raise each element by (sign is retained) where the numerator is 1. This is useful for mellowing out the extremes. |
keep.zero |
logical. If |
sign |
logical. If |
... |
ignored. |
Returns a rescaled vector of the same length as x
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | general_rescale(c(1, 0, -1))
general_rescale(c(1, 0, -1, 1.4, -2))
general_rescale(c(1, 0, -1, 1.4, -2), lower = 0, upper = 1)
general_rescale(c(NA, -4:3))
general_rescale(c(NA, -4:3), keep.zero = FALSE)
general_rescale(c(NA, -4:3), keep.zero = FALSE, lower = 0, upper = 100)
## mute extreme values
set.seed(10)
x <- sort(c(NA, -100, -10, 0, rnorm(10, 0, .1), 10, 100), na.last = FALSE)
general_rescale(x)
general_rescale(x, mute = 5)
general_rescale(x, mute = 10)
general_rescale(x, mute = 100)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.