Skip to contents

Rescales a numeric vector to a new range.

Usage

rescale_vector(
  x = NULL,
  new.min = 0,
  new.max = 1,
  integer = FALSE
)

Arguments

x

Numeric vector. Default: NULL

new.min

New minimum value. Default: 0

new.max

New maximum value. Default: 1

integer

Logical, if TRUE, coerces the output to integer. Default: FALSE

Value

A numeric vector of the same length as x, but with its values rescaled between new.min and new.max.

Examples


y <- rescale_vector(
  x = rnorm(100),
  new.min = 0,
  new.max = 100,
  integer = TRUE
)
y
#>   [1] 100  60  34  40  87  43  63   3  55  29  24  70  33  71  45  53  64  79
#>  [19]  28   0  66  59  38  68  46  45  41  69  65  37  54  62  58  34  35  44
#>  [37]  37  81  45  68   6  64  33  24  77  39  41  59  67  11  76  73  38  40
#>  [55]  47  62  37   0  51  56  34  66  16  37  21  27  66  43  73  66  58  56
#>  [73]  29  36  32  66  27  42  14  45  53  27  39  26  14   5  25  42  87  13
#>  [91]  72  90  26  21  58  46  16  59  50  55