Clip (i.e., limit) the values in a vector, matrix, or array.
Value
Returns x
with values outside the interval
[.min
, .max
] clipped to the interval edges. That is, values
in x
smaller than .min
become .min
, and values larger
than .max
become .max
.
Examples
clip(1:10, 3, 8) # [1] 3 3 3 4 5 6 7 8 8 8
#> [1] 3 3 3 4 5 6 7 8 8 8
clip(randn(5, 5), .min = -1, .max = 1)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.6215527 -0.2827054 0.51242695 -0.9140748 1.00000000
#> [2,] 1.0000000 -0.5536994 -1.00000000 0.4681544 -0.09744510
#> [3,] -1.0000000 0.6289820 -0.52201251 0.3629513 -0.93584735
#> [4,] -0.2473253 1.0000000 -0.05260191 -1.0000000 -0.01595031
#> [5,] -0.2441996 -1.0000000 0.54299634 0.7377763 -0.82678895