Skip to contents

This package contains the function standardize(). This function is useful for a variety of data processing applications where centering and scaling your data is important. For example, you may want to use this function before inputting a vector to a KNN algorithm. To use the standardize function, simply input a vector x like so:

x <- get("rand_data")
x_center_scale <- standardize(x)
print(x_center_scale)
#>   [1]  0.402526047  1.398387882  0.348501037 -1.243133972 -0.270627714
#>   [6] -1.262316016  0.066987865 -1.033019943  0.501685944  0.871580263
#>  [11]  1.225749870 -0.492954012  1.250179451 -0.083575512  0.490326238
#>  [16] -1.373660702  0.217007945 -0.993418868 -0.572341140 -0.537966422
#>  [21] -0.994528640  0.021952660  1.720113579  1.618123864 -0.172342952
#>  [26] -0.551017787 -0.964557176  1.624009652 -0.838998070  0.008599081
#>  [31] -0.652526952  0.753215117  0.394305305  0.125694836  0.924664949
#>  [36]  0.241416812 -0.510480230 -0.094792025 -1.352104116  0.860053559
#>  [41] -2.266553148 -0.228180789  0.229205116 -0.143265105 -0.059500671
#>  [46] -1.642857739  1.175465474 -1.369579501 -0.982281848 -0.767272829
#>  [51] -0.273373170 -0.898350856 -0.230018700  1.736256995 -1.413670018
#>  [56] -0.827346361  1.280529582  0.870628412  0.611578004  0.326602052
#>  [61]  2.480962114  1.213686860  1.167102628 -0.579029073 -1.629792373
#>  [66]  1.080192476 -1.589414518 -1.861953193 -0.565152793 -1.185025551
#>  [71]  1.716468777 -0.450298761  0.508592837 -0.305035711  0.049382512
#>  [76] -0.371423146 -0.355344256 -0.311977610  1.502929516 -0.227680249
#>  [81]  1.607967525  1.355196212 -0.619823911  2.049767470 -1.017849667
#>  [86]  0.767336409 -0.090409428  0.913377994 -0.579442948 -0.277199630
#>  [91]  0.158316890 -0.630829709  0.250392758 -1.664432321  0.892050211
#>  [96]  0.686964201 -0.460482472 -0.648765396 -0.476658663  1.298599380
print(mean(x_center_scale))
#> [1] 2.664535e-17
print(sd(x_center_scale))
#> [1] 1

Now x_center_scale will be x but with mean of 0 and standard deviation of 1, as desired.