Skip to contents

Normalize a numeric vector. normalize() defaults to [0, 1] normalization. normalize_maxabs() returns maximum absolute normalization.

Usage

normalize(x, lower = 0, upper = 1)

normalize_maxabs(x)

Arguments

x

A numeric vector.

lower

A numeric for the lower bound.

upper

A numeric for the upper bound.

Value

numeric vector

Examples

#----------------------------------------------------------------------------
# normalize() examples
#----------------------------------------------------------------------------
library(bkstat)

x <- rnorm(100, mean = 30, sd = 50)
normalize(x)
#>   [1] 0.3925187 0.6103900 0.5224805 0.6768375 0.6996978 0.4211998 0.3089999
#>   [8] 0.5294412 0.5367619 0.6939313 0.4291944 0.5155668 0.6127790 0.3974405
#>  [15] 0.2126166 0.6693910 0.7431115 0.4272370 0.7106217 0.7744685 0.3199554
#>  [22] 0.4383432 0.8037401 0.2382861 0.5383212 0.6582535 0.3889845 0.2882535
#>  [29] 0.4897274 0.7357823 0.3830551 0.4353400 0.3847247 0.7258569 0.4027457
#>  [36] 0.6128654 0.4779978 0.5652230 0.0000000 0.3862415 0.4183816 0.3383843
#>  [43] 0.9460180 0.3173963 0.4870738 0.4077250 0.4484594 0.9550853 0.5063369
#>  [50] 0.7180617 0.5678123 0.4720178 0.4784861 0.7032999 0.6405853 0.6990863
#>  [57] 0.4444095 0.8364458 0.5465051 0.4721310 0.4719886 1.0000000 0.5088756
#>  [64] 0.4158361 0.6530388 0.4684194 0.5351015 0.7323052 0.2334349 0.3994055
#>  [71] 0.3249561 0.4115603 0.4797851 0.2343632 0.7317855 0.7470644 0.6501155
#>  [78] 0.2488130 0.2445359 0.8158440 0.4229472 0.5223915 0.6126104 0.4723572
#>  [85] 0.5028647 0.6809395 0.3816868 0.8871949 0.2395652 0.2149915 0.3645579
#>  [92] 0.5717301 0.3422043 0.3022518 0.2428123 0.5895498 0.7202123 0.4846072
#>  [99] 0.6746652 0.6997820
normalize_maxabs(x)
#>   [1] -0.084268630  0.304600918  0.147694790  0.423200338  0.464002873
#>   [6] -0.033076936 -0.233337949  0.160118726  0.173185195  0.453710451
#>  [11] -0.018807634  0.135354832  0.308864913 -0.075483879 -0.405368653
#>  [16]  0.409909433  0.541490079 -0.022301474  0.483500432  0.597457905
#>  [21] -0.213784020 -0.002478351  0.649703730 -0.359552135  0.175968208
#>  [26]  0.390030586 -0.090576676 -0.270367328  0.089235175  0.528408549
#>  [31] -0.101159921 -0.007838609 -0.098179942  0.510693193 -0.066015018
#>  [36]  0.309019236  0.068299532  0.223984185 -0.784859367 -0.095472665
#>  [41] -0.038106994 -0.180890979  0.903649790 -0.218351566  0.084498845
#>  [46] -0.057127557  0.015577564  0.919833489  0.118880752  0.496779872
#>  [51]  0.228605760  0.057625939  0.069171021  0.470432003  0.358495284
#>  [56]  0.462911452  0.008349031  0.708078821  0.190575390  0.057828156
#>  [61]  0.057573894  1.000000000  0.123412040 -0.042650375  0.380723120
#>  [66]  0.051203415  0.170221520  0.522202381 -0.368210832 -0.071976694
#>  [71] -0.204858413 -0.050282045  0.071489524 -0.366554100  0.521274754
#>  [76]  0.548545593  0.375505315 -0.340763160 -0.348397136  0.671307464
#>  [81] -0.029958143  0.147536045  0.308564052  0.058231823  0.112683379
#>  [86]  0.430521814 -0.103602171  0.798658749 -0.357269136 -0.401129717
#>  [91] -0.134174753  0.235598480 -0.174072854 -0.245382498 -0.351473504
#>  [96]  0.267404037  0.500618242  0.080096336  0.419323091  0.464153038