Learn R Programming

prepkit (version 0.1.1)

norm_mean: Mean Normalization

Description

Scales a numeric vector by centering it around its mean and scaling it by its range. The resulting vector has a mean of 0 and values typically within [-1, 1].

Usage

norm_mean(x, na.rm = TRUE)

Value

A numeric vector. If the range is 0 (all values are identical), returns a centered vector (zeros).

Arguments

x

A numeric vector.

na.rm

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

Details

Formula: \(x' = \frac{x - \text{mean}(x)}{\max(x) - \min(x)}\)

References

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

Examples

Run this code
# Result ranges from approx -0.5 to 0.5, mean is 0
norm_mean(c(1, 2, 3, 4, 5))

# Handles negative values
norm_mean(c(-10, 0, 10))

Run the code above in your browser using DataLab