Description Usage Arguments Details Value Examples
Force all elements of the input value to be within the specified range.
1 | forceRange(x, min=-Inf, max=Inf)
|
x |
A numeric vector, matrix, or data frame, possibly containing values less that |
min |
The minimum value. |
max |
The maximum value. |
forceRange
will replace all elements of x
less than min
with min
, and all elements of x
greater than max
with max
. If the default parameters are used, x
will be returned unchanged.
A matrix, vector, or data frame.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | set.seed(123)
x = rnorm(12)
y = matrix(x, ncol=4)
y
# [,1] [,2] [,3] [,4]
# [1,] -0.5604756 0.07050839 0.4609162 -0.4456620
# [2,] -0.2301775 0.12928774 -1.2650612 1.2240818
# [3,] 1.5587083 1.71506499 -0.6868529 0.3598138
forceRange(x, 0)
# [1] 0.00000000 0.00000000 1.55870831 0.07050839 0.12928774 1.71506499
# [7] 0.46091621 0.00000000 0.00000000 0.00000000 1.22408180 0.35981383
forceRange(y, -1, 1)
# [,1] [,2] [,3] [,4]
# [1,] -0.5604756 0.07050839 0.4609162 -0.4456620
# [2,] -0.2301775 0.12928774 -1.0000000 1.0000000
# [3,] 1.0000000 1.00000000 -0.6868529 0.3598138
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.