clip(X;Y;Z)
Returns NA if X is "out of
bounds", that is, X<Y or X>Z.
Otherwise, clip(X;Y;Z) returns X.
(Available as of version 18.37)
Syntax
clip(X;Y;Z)
Input
| Argument | Type | Description |
|---|---|---|
X |
any simple type | The value to be "clipped". |
Y |
any simple type | The minimum allowed value. |
Z |
any simple type | The maximum allowed value. |
Return Value
Returns NA if X is "out of bounds",
that is, less than the minimum (Y) or greater than
the maximum (Z). Otherwise,
clip(X;Y;Z) returns X.
clip(X;Y;Z) is the equivalent of
if(between(X;Y;Z);X;na).
Sample Usage
value |
min |
max |
clip(value;min;max) |
|---|---|---|---|
| 2 | 1 | 3 | 2 |
| 2 | 3 | 1 | NA |
| 1.5 | 1 | 3 | 1.5 |
| 1.5 | 2.5 | 3.1 | NA |
| 1.5 | 1.2 | 3.1 | 1.5 |
| 'bat' | 'bar' | 'baz' | 'bat' |
| 'bag' | 'bar' | 'baz' | NA |
| 'foo' | 'bar' | 'baz' | NA |
| 3 | 'foo' | 'bar' | NA |
| 3 | 4 | 'foo' | NA |
