clamp: Clamp

View source: R/skUtils.R

clampR Documentation

Clamp

Description

Clamp a numeric vector between a minimum and maximum value.

Usage

clamp(x, minval = -Inf, maxval = Inf)

clamp0(x, minval = 0, maxval = 1)

scale2range(x, minval = 0, maxval = 1, na.rm = TRUE)

Arguments

x

The vector/matrix to clamp.

minval

Minimum value; all lower values are clamped to this value.

maxval

Maximum value; all higher values are clamped to this value.

na.rm

for scale2range, whether NAs should be removed before applying the function (default TRUE. If FALSE and x contains NAs, then the complete vector will be NA.

Value

Clamped vector.

Functions

  • clamp(): Set all values exceeding the minimum and maximum to the minimum and maximum value, respectively.

  • clamp0(): Same as clamp()) but with a default range of 0 to 1.

  • scale2range(): Rescales the vector such that it fits neatly between the given minimum and maximum values.

Author(s)

Sercan Kahveci

Examples

clamp(0:10,2,8)
clamp0(rnorm(10))
scale2range(rnorm(10))


Spiritspeak/skMisc documentation built on April 12, 2025, 5:40 a.m.