rescale | R Documentation |
Rescales numbers from one scale to another. By default, assumes that the old scale has min and max values represented in the vector, but this can be overwritten.
rescale(
x,
new_min,
new_max,
old_min = min(x, na.rm = T),
old_max = max(x, na.rm = T)
)
x |
(num vectr) A vector of values. |
new_min |
(num sclr) The new scale minimum. |
new_max |
(num sclr) The new scale maximum. |
old_min |
(num sclr) The old scale minimum. Default: min(x). |
old_max |
(num sclr) The old scale maximum. Default: max(x). |
rescale(1:10, new_min = 0, new_max = 1) #converts to 0, ..., 1
rescale(1:10, new_min = 0, new_max = 5) #converts to 0, ..., 5
rescale(rnorm(10), new_min = 1, new_max = 100) %>% sort #converts to 1, ..., 1
rescale(c(.1, .5, 1), new_min = 10, new_max = 20, old_min = 0, old_max = 1) #assume old numbers belong to scale 0-1, rescale to 10-20 scale, i.e. 11, 15, 20
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.