powered by
Restricts x to the interval [min_val, max_val]. Values outside the range are replaced by the nearest bound.
x
[min_val, max_val]
clamp(x, min_val, max_val, warn = TRUE, param_name = "value")
x with values outside [min_val, max_val] replaced by the bounds
Numeric value or vector
Lower bound
Upper bound
Logical; issue a warning when clamping occurs, default TRUE
Name used in warning messages
suppressWarnings(clamp(1.5, 0, 1)) suppressWarnings(clamp(-0.5, 0, 1)) clamp(0.3, 0, 1) suppressWarnings(clamp(c(-1, 0.5, 2), 0, 1))
Run the code above in your browser using DataLab