Function standardizes numeric vector using multiple methods

standardize(x, method = "zs", na.rm = FALSE)

Arguments

x

Numeric vector

method

Character string. Default is 'zs' (for z-score method). Other options include '01' (0 to 1 scaling) and 'pr' (percent rank)

na.rm

Should NAs be removed? Default is FALSE

Value

Numeric vector with standardized values

Examples

x <- c(1, 4, 5, 6, 2, 4, 10, 12, 5) standardize(x)
#> [1] -1.2556843 -0.4080974 -0.1255684 0.1569605 -0.9731553 -0.4080974 1.2870764 #> [8] 1.8521343 -0.1255684
standardize(x, method = "01")
#> [1] 0.00000000 0.27272727 0.36363636 0.45454545 0.09090909 0.27272727 0.81818182 #> [8] 1.00000000 0.36363636
standardize(x, method = "pr")
#> [1] 0.000 0.250 0.500 0.750 0.125 0.250 0.875 1.000 0.500