From every element in a vector, subtract center
and
divide by scale
.
scale_vector(y, center = mean, scale = sd)
y | A numeric vector. |
---|---|
center | Either a function that computes center of data
(such as |
scale | Either a function that computes variability of data
(such as |
The same object as y
just with every element scaled
y <- 1:10 scale_vector(y)#> [1] -1.4863011 -1.1560120 -0.8257228 -0.4954337 -0.1651446 0.1651446 #> [7] 0.4954337 0.8257228 1.1560120 1.4863011scale_vector(y, center = median, scale = IQR)#> [1] -1.0000000 -0.7777778 -0.5555556 -0.3333333 -0.1111111 0.1111111 #> [7] 0.3333333 0.5555556 0.7777778 1.0000000scale_vector(y, center = 10, scale = 2)#> [1] -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0