confined {DMTL}R Documentation

Restrict data in a given interval

Description

This function filters a data vector using a given interval so that only the values falling inside the interval remains and any value that is less than the leftmost end gets replaced by that end-value, and similarly, any value greater than the rightmost end gets replaced by that end-value.

Usage

confined(x, lims = c(0, 1))

Arguments

x

Vector containing data.

lims

Limit for the values. Values falling within this limit will pass without any change. Any value x < lims[1] will get replaced by lims[1], and any value x > lims[2] will get replaced by lims[2]. Defaults to c(0, 1).

Value

The filtered vector.

Examples

x <- rnorm(100, 0, 1)
x_filt <- confined(x, lims = c(-0.5, 0.5))
print(range(x_filt))


[Package DMTL version 0.1.2 Index]