Computes z-score (standardized scores)

zscore(x, n = 0)

Arguments

x

A vector

n

use n or n-1 in the denominator when computing SD (default 0 for n; use -1 for n = -1)

Value

A vector

Note

Formula: (x - mean(x)) / SD(x)

Author

Hause Lin

Examples

zscore(1:10)
#> [1] -1.5666989 -1.2185436 -0.8703883 -0.5222330 -0.1740777 0.1740777 #> [7] 0.5222330 0.8703883 1.2185436 1.5666989
zscore(1:10, n = 0) # default n = 0 (SD is computed using n)
#> [1] -1.5666989 -1.2185436 -0.8703883 -0.5222330 -0.1740777 0.1740777 #> [7] 0.5222330 0.8703883 1.2185436 1.5666989
zscore(1:10, n = -1) # n = -1 (SD is computed using n-1)
#> [1] -1.4863011 -1.1560120 -0.8257228 -0.4954337 -0.1651446 0.1651446 #> [7] 0.4954337 0.8257228 1.1560120 1.4863011