Standardize a variable by subtracting the mean and dividing by the standard deviation
standardize(x, na.rm = FALSE)
A vector of standardized numbers
x <- runif(10)
standardize(x)
#> [1] 0.0338459 -1.2208602 -1.0098707 1.0133263 0.9246266 1.1173084
#> [7] 1.0834942 -0.7880408 -1.2468939 0.0930641
x[1] <- NA
standardize(x, na.rm = TRUE)
#> [1] NA -1.1475736 -0.9486368 0.9589866 0.8753538 1.0570288
#> [7] 1.0251462 -0.7394787 -1.1721201 0.0912937