Learn R Programming

prepkit (version 0.1.1)

norm_zscore: Z-Score Standardization

Description

Standardizes a numeric vector by centering it to have a mean of 0 and scaling it to have a standard deviation of 1.

Usage

norm_zscore(x, na.rm = TRUE)

Value

A numeric vector. If the input vector has zero variance (all values are identical), the function returns a centered vector (all zeros) and issues a warning.

Arguments

x

A numeric vector.

na.rm

Logical. Should NA values be removed during mean/sd calculation? Default is TRUE.

Details

Formula: \(z = \frac{x - \mu}{\sigma}\)

References

Han, J., Kamber, M., & Pei, J. (2011). Data mining: concepts and techniques (3rd ed.). Morgan Kaufmann.

Examples

Run this code
# Standard usage
norm_zscore(c(1, 2, 3, 4, 5))

# Edge case: Zero variance
norm_zscore(c(5, 5, 5))

Run the code above in your browser using DataLab