clip!
Syntax
clip!(X,Y,Z)
Arguments
X is a vector/matrix/table.
Y is a scalar/vector/matrix/table.
Z is a scalar/vector/matrix/table.
-
If X is a vector, Y and Z can be scalars or vectors of the same length as X.
-
If X is a matrix, Y and Z can be scalars or vectors with a length equal to the row number of X, matrices with the same dimensions as X.
-
If X is a table, Y and Z can be scalars or vectors with a length equal to the row number of X, tables with the same dimensions as X.
Details
Clip the values to be within a specified range. In X, values outside the range [Y, Z] are clipped to the interval edges.
-
Values in X smaller than Y will be replaced by Y. If Y is a NULL scalar, no replacement will be done.
-
Values in X greater than Z will be replaced by Z. If Z is a NULL scalar, no replacement will be done.
-
If Y or Z is a vector containing NULLs, values in X with the same index will be replaced by NULLs.
-
If Z is smaller than Y, values in X' will be replaced by Z.
If X is a matrix or table, the aforementioned calculations will be performed on each column and the values of X will be modified.
Note: If the data type of Y or Z is inconsistent with that of X, values may be rounded or overflowed.
Examples
x = 1..9
y = 3
z = 7
clip!(x,y,z)
print(x)
// output
[3,3,3,4,5,6,7,7,7]
x = 1..9
y = 3
z = NULL
clip!(x,y,z)
print(x)
// output
[3,3,3,4,5,6,7,8,9]
x = 1..9$3:3
y = [1,3,3,3,,5,6,7,8]$3:3
z = [2,4,5,5,6,7,,6,10]$3:3
clip!(x,y,z)
print(x)
// output
#0 #1 #2
-- -- --
1 4
3 6
3 6 9
x = table(1..3 as x1, 4..6 as x2, 7..9 as x3)
y = table([1.0,3.5,3.0] as y1, [3,,5] as y2, [6,7,8] as y3)
z = table([2,4,5] as z1, [5,6,7] as z2, [,6,10] as z3)
clip!(x,y,z)
print(x)
// output
x1 x2 x3
--- -- --
1.0 4
3.5 6
3.0 6 9
x = [1,2,3]
x.clip!(1.1,2.2)
// output
[1,2,2]