min_max_scale {rearrr}R Documentation

Scale to a range

Description

[Experimental]

Scales the values to a range with MinMax scaling.

Usage

min_max_scale(
  x,
  new_min,
  new_max,
  old_min = NULL,
  old_max = NULL,
  na.rm = FALSE
)

Arguments

x

Numeric vector to scale.

new_min

Minimum value of target range.

new_max

Maximum value of target range.

old_min

Minimum value of original range.

If NULL, this is the minimum value in `x`.

old_max

Maximum value of original range.

If NULL, this is the maximum value in `x`.

na.rm

Whether missing values should be removed when calculating `old_min` and/or `old_max`.

N.B. Ignored when both `old_min` and `old_max` are NULL.

Value

Scaled version of `x`.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

See Also

Other scaling functions: to_unit_length()

Examples

# Attach packages
library(rearrr)

# Set seed
set.seed(1)

# Create numeric vector
x <- runif(10)

# Scale
min_max_scale(x, new_min = -1, new_max = 0)
min_max_scale(x, new_min = -1, new_max = 0, old_max = 3)

[Package rearrr version 0.3.4 Index]