Rescale a numeric vector

center(x, ...)

unit_range(x, ...)

unit_length(x, na.rm = TRUE)

Arguments

x

a numeric vector

...

additional arguments passed to scale for center or max and min for unit_range.

na.rm

if TRUE, unit_length calculates the L2 norm based on the non-missing elements of x.

Value

a rescaled version of x.

Details

center

\(\frac{x - mean(x)}{sd(x)}\)

unit_range

\(\frac{x - min(x)}{max(x) - min(x)}\)

unit_length

\(\frac{x}{|| x ||}\)

References

https://en.wikipedia.org/wiki/Normalization_(statistics)

Examples

center(1:10)
#> [1] -1.4863011 -1.1560120 -0.8257228 -0.4954337 -0.1651446 0.1651446 #> [7] 0.4954337 0.8257228 1.1560120 1.4863011
unit_range(1:10)
#> [1] 0.0000000 0.1111111 0.2222222 0.3333333 0.4444444 0.5555556 0.6666667 #> [8] 0.7777778 0.8888889 1.0000000
unit_length(1:10)
#> [1] 0.05096472 0.10192944 0.15289416 0.20385888 0.25482360 0.30578831 #> [7] 0.35675303 0.40771775 0.45868247 0.50964719