Learn R Programming

LW1949 (version 1.1.0)

constrain: Constrain Data to a Specified Range

Description

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

Usage

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.

Value

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

Run this code
constrain(1:20, c(3, 19))

Run the code above in your browser using DataLab