Skip to contents

Clips a numeric vector to specified upper and lower bounds. Use for constraining values in weighting, imputation, or error checking.

Usage

clip.vector(vec, ub = -Inf, lb = Inf, na.rm = FALSE)

Arguments

vec

numeric vector. Values to clip.

ub

numeric(1). Upper bound (default -Inf).

lb

numeric(1). Lower bound (default Inf).

na.rm

logical(1). Remove NA values (default FALSE).

Value

numeric vector. Clipped values.

Details

  • Applies pmin and pmax to enforce bounds.

  • Optionally removes NA values.

  • Returns clipped vector; does not modify input by reference.

Settings

None.

See also

fillna

Other utility functions: archive_file(), fillna(), weighted.median(), weighted.percentile()

Examples

clip.vector(c(-1, 0, 5), ub = 3, lb = 0)
#> [1] 0 0 3