set.seed(123)
x <- rnorm(5)
# Default 0~1 range
rescale_to_range(x)
# Rescale to -1~1
rescale_to_range(x, to = c(-1, 1))
# Preserve NAs but ignore them when determining the range
x_with_na <- c(x, NA, 10)
rescale_to_range(x_with_na, to = c(0, 100))
Run the code above in your browser using DataLab