Rescale numeric vector to have specified minimum and maximum, but allow for hard boundaries. It is a slightly modified version of scales::rescale, incorporating scales::zero_range, both by Hadley Wickham used under the conditions of the MIT license.
rescale(
x,
to = c(0, 1),
from = range(x, na.rm = TRUE, finite = TRUE),
hard_bounds = TRUE
)
values to rescale
range to scale to
range of values the x could have been
If TRUE
, all values will be forced into the range of to
.