constrain function

Constrain Data to a Specified Range

Constrain Data to a Specified Range

Constrain data to a specified range, assigning values from the specified range to those outside the range, typically for graphing purposes.

constrain(x, xrange)

Arguments

  • x: A numeric vector of values to constrain.
  • xrange: A numeric vector of length two specifying the constraints, the minimum and maximum value for x.

Returns

A numeric vector, the same length as x, in which the minimum constraint is assigned to values of x less than the minimum, and the maximum constraint is assigned to values of x greater than the maximum.

Examples

constrain(1:20, c(3, 19))
  • Maintainer: Jean V. Adams
  • License: GPL
  • Last published: 2017-03-20