Normalize numeric vector

normalization(x, method = "max_min", na_rm = TRUE)

Arguments

x

Input numeric vector.

method

Method used for normalization.

na_rm

Whether to remove NA values, and if setting TRUE, using 0 instead.

Value

Normalized numeric vector

Examples

nums <- c(runif(2), NA, -runif(2))
nums
#> [1]  0.6627989130  0.0006031182            NA -0.4749383451 -0.6205798867
normalization(nums, method = "max_min")
#> [1] 1.0000000 0.4840216 0.4835516 0.1134829 0.0000000
normalization(nums, method = "maximum")
#> [1]  1.0000000000  0.0009099566  0.0000000000 -0.7165647617 -0.9363019078
normalization(nums, method = "sum")
#> [1]  0.3768214665  0.0003428912  0.0000000000 -0.2700169844 -0.3528186580
normalization(nums, method = "softmax")
#> [1] 0.3804064 0.1961823 0.1960640 0.1219368 0.1054104
normalization(nums, method = "z_score")
#> [1]  1.4890603  0.1729627  0.1717640 -0.7721640 -1.0616229
normalization(nums, method = "mad")
#> [1]  0.9412837408  0.0008565273  0.0000000000 -0.6744907595 -0.8813257624
normalization(nums, method = "unit_vector")
#> [1]  0.6468290219  0.0005885863  0.0000000000 -0.4634948839 -0.6056272472
normalization(nums, method = "unit_vector", na_rm = FALSE)
#> [1]  0.6468290219  0.0005885863            NA -0.4634948839 -0.6056272472