trim: Trim extreme values

Description Usage Arguments Value Note Author(s) Examples

Description

Trim extreme values from an atomic vector, and replace with a specific value (typically NA_*).

Usage

1
trim_numeric(x, bounds = c(-Inf, Inf), replacement = NA_real_)

Arguments

x

The input vector to be trimmed. Required

bounds

A two-element vector that establishes the lower and upper inclusive bounds of x.

replacement

A scalar that will replace all instances of x that fall outside of bounds.

Value

An atomic vector with the same number of elements as x.

Note

The data type of x, bounds, and replacement must match the atomic data type of the function. In other words, trim_numeric() accepts only parameters of type 'numeric' (otherwise known as 'double-precision floating point'). Likewise, trim_date() accepts only parameters of type Date.

The lower bound must be less than or equal the upper bound.

The default bounds for numerics and integers are at the extremes of the data type. The default bounds for dates are arbitrary, because the origin is slippery.

Author(s)

Will Beasley

Examples

1
2
library(sweepspecify)
trim_numeric(runif(10, -1, 10), bounds=c(4, 8))

OuhscBbmc/sweepspecify documentation built on May 28, 2019, 5:39 a.m.