Description Usage Arguments Details Examples
Linearly map (scale) one or more numbers from one range to another range. This is the same as linear interpolation.
1 2 3 4 5 6 7 | linear_map(
x,
in_start = min(x, na.rm = TRUE),
in_end = max(x, na.rm = TRUE),
out_start = 0,
out_end = 1
)
|
x |
A numeric vector. |
in_start, in_end |
The limits of the input range, defaults to
|
out_start, out_end |
The limits of the output range, defaults to 0 and 1. |
If the input is outside the input range then it will be outside the output range, too.
Can also map to ranges where start > end
(see examples).
1 2 3 4 5 6 7 8 | linear_map(1:3) # 0, 0.5, 1
linear_map(1:3, 0, 10) # 0.1, 0.2, 0.3
linear_map(1:3, 1, 10) # 0, 0.11, 0.22
linear_map(1:3, 0, 10, 0, 100) # 10, 20, 30
linear_map(-1, 0, 1, 20, 30) # 10
# Ranges may also go from high to low values (inverts the result):
linear_map(1:3, out_start = 30, out_end = 10) # 30, 20, 10)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.