Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

range01

Shrink or stretch a vector to make it range between 0 and 1


Description

This function re-scales a numeric vector so that it ranges between 0 and 1 (i.e., the lowest value becomes 0, the highest becomes 1, and the ones in the middle retain their rank and relative diference).

Usage

range01(x, na.rm = TRUE)

Arguments

x

a numeric vector.

na.rm

logical, whether to remove NA values.

Details

This function was borrowed from http://stackoverflow.com/questions/5468280/scale-a-series-between-two-points-in-r/5468527#5468527 and adapted to handle also missing values.

Value

A numeric vector of the same length as the input, now with the values ranging from 0 to 1.

Author(s)

A. Marcia Barbosa

See Also

Examples

range01(0:10)

range01(-12.3 : 21.7)

modEvA

Model Evaluation and Analysis

v2.0
GPL-3
Authors
Barbosa A.M., Brown J.A., Jimenez-Valverde A., Real R.
Initial release
2020-01-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.