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

If X is a vector, return a vector X' of the same length.

  • 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 return a matrix or table with the same dimensions.

Examples

x = 1..9
y = 3
z = 7
clip(x,y,z)
// output
[3,3,3,4,5,6,7,7,7]

x = 1..9
y = 3
z = NULL
clip(x,y,z)
// 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)
// 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)
// output
x1  x2 x3
--- -- --
1.0 4    
3.5    6 
3.0 6  9