normScale | R Documentation |
Scale a numeric vector from 0 to 1
normScale(
x,
from = 0,
to = 1,
low = min(x, na.rm = TRUE),
high = max(x, na.rm = TRUE),
naValue = NA,
singletMethod = c("mean", "min", "max"),
...
)
x |
|
from |
the minimum |
to |
the maximum |
low |
|
high |
|
naValue |
optional |
singletMethod |
|
... |
additional parameters are ignored. |
This function is intended as a quick way to scale numeric values between 0 and 1, however other ranges can be defined as needed.
NA values are ignored and will remain NA in the output. To handle
NA values, use the rmNA()
function, which can optionally replace
NA with a fixed numeric value.
The parameters low
and high
are used optionally to provide a
fixed range of values expected for x
, which is useful for
consistent scaling of x
. Specifically, if x
may be a
vector of numeric values ranging from 0 and 100, you would
define low=0
and high=100
so that x
will be consistently
scaled regardless what actual range is represented by x
.
Note that when x
contains only one value, and low
and high
are not defined, then x
will be scaled based upon the
argument singletMethod
. For example, if you provide x=2
and want to scale x
values to between 0 and 10... x
can
either be the mean
value 5
; the min
imum value 0
; or
the max
imum value 10
.
However, if low
or high
are defined, then x will be scaled
relative to that range.
Other jam numeric functions:
deg2rad()
,
fix_matrix_ratio()
,
noiseFloor()
,
rad2deg()
,
rowGroupMeans()
,
rowRmMadOutliers()
,
warpAroundZero()
# Notice the first value 1 is re-scaled to 0
normScale(1:11);
# Scale values from 0 to 10
normScale(1:11, from=0, to=10);
# Here the low value is defined as 0
normScale(1:10, low=0);
normScale(c(10,20,40,30), from=50, to=65);
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.