Learn R Programming

omnibus (version 1.2.15)

stretchMinMax: Rescale values

Description

This function rescales a vector of numeric values to an arbitrary range. Optionally, after the stretch values equal to the lowest value can be "nudged" slightly higher to half the minimum value across the rescaled vector of values > 0.

Usage

stretchMinMax(
  x,
  lower = 0,
  upper = 1,
  nudgeUp = FALSE,
  nudgeDown = FALSE,
  na.rm = FALSE
)

Value

Numeric value.

Arguments

x

Numeric list.

lower

Numeric, low end of range to which to stretch.

upper

Numeric, high end of range to which to stretch.

nudgeUp, nudgeDown

Logical, if FALSE (default) then do nothing. If TRUE then *after* rescaling to [0, 1], a small value will be added to all values of x equal to 0. This value is equal to 0.5 * min(x[x > 0]).

na.rm

Logical, if FALSE (default) then if any values of x are NA then the returned value will be NA. If TRUE then NA's are ignored in calculation.

See Also

Examples

Run this code

x <- 1:10
stretchMinMax(x)
stretchMinMax(x, lower=2, upper=5)
stretchMinMax(x, nudgeUp=TRUE)
stretchMinMax(x, lower=2, upper=5, nudgeUp=TRUE)
stretchMinMax(x, nudgeDown=TRUE)
stretchMinMax(x, lower=2, upper=5, nudgeUp=TRUE, nudgeDown=TRUE)
x <- c(1:5, NA)
stretchMinMax(x)
stretchMinMax(x, na.rm=TRUE)

Run the code above in your browser using DataLab