Rescale a numeric variable to a new range.

change_scale(x, ...)

# S3 method for numeric
change_scale(x, to = c(0, 100), range = NULL, verbose = TRUE, ...)

# S3 method for grouped_df
change_scale(
  x,
  select = NULL,
  exclude = NULL,
  to = c(0, 100),
  range = NULL,
  ...
)

# S3 method for data.frame
change_scale(
  x,
  select = NULL,
  exclude = NULL,
  to = c(0, 100),
  range = NULL,
  ...
)

Arguments

x

Object.

...

Arguments passed to or from other methods.

to

New range of values of the data after rescaling.

range

Initial (old) range of values. If NULL, will take the range of data.

verbose

Toggle warnings and messages on or off.

select

Character vector of column names. If NULL (the default), all variables will be selected.

exclude

Character vector of column names to be excluded from selection.

Value

A rescaled object.

See also

Examples

change_scale(c(0, 1, 5, -5, -2))
#> [1]  50  60 100   0  30
change_scale(c(0, 1, 5, -5, -2), to = c(-5, 5))
#> [1]  0  1  5 -5 -2

head(change_scale(trees))
#>       Girth    Height     Volume
#> 1  0.000000 29.166667  0.1497006
#> 2  2.439024  8.333333  0.1497006
#> 3  4.065041  0.000000  0.0000000
#> 4 17.886179 37.500000  9.2814371
#> 5 19.512195 75.000000 12.8742515
#> 6 20.325203 83.333333 14.2215569