The standardize()
function allows you to easily scale and center all numeric variables of a dataframe. It is similar to the base function scale()
, but presents some advantages: it is tidyverse-friendly, data-type friendly (i.e., does not transform it into a matrix) and can handle dataframes with categorical data.
library(psycho) library(tidyverse) z_iris <- iris %>% psycho::standardize() summary(z_iris)
But beware, standardization does not change (and "normalize") the distribution!
z_iris %>% dplyr::select(-Species) %>% gather(Variable, Value) %>% ggplot(aes(x=Value, fill=Variable)) + geom_density(alpha=0.5) + geom_vline(aes(xintercept=0)) + theme_bw() + scale_fill_brewer(palette="Spectral")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.