Standardize a variable by subtracting the mean and dividing by the standard deviation

standardize(x, na.rm = FALSE)

Arguments

x

A numeric vector

na.rm

A boolean equal to TRUE if ignore NA when calculating the mean and standard deviations. See mean and sd

Value

A vector of standardized numbers

Examples

x <- runif(10)
standardize(x)
#>  [1] -0.311336  0.836153 -1.153833  0.748621 -0.903185  1.422040 -0.273757
#>  [8] -1.156613  1.330823 -0.538913

x[1] <- NA
standardize(x, na.rm = TRUE)
#>  [1]        NA  0.760281 -1.127223  0.677257 -0.889484  1.315995 -0.292470
#>  [8] -1.129860  1.229476 -0.543971