I have a dataset that looks something like this: but with hundred of variables
set.seed(123)
df <- data.frame(id= c(1,1,1,2,2,2,3,3,3), time=c(1,2,3,1,2,3,1,2,3),y = rnorm(9), x1 = rnorm(9), x2 = c(0,0,0,0,1,0,1,1,1), x3 = rnorm(9), c1 = rnorm(9), c2 = rnorm(9))
I would like to standardize all my variables to ease interpretation after regression.
I know I could standardize variable one by one using BBmisc
library(BBmisc)
df$z_y <- normalize(df$y, method = "standardize")
But this would result quite tedious long and disorganized in the command file.
Since I am not really able to use loops or functions, I was wondering whether someone would know how to do it in a single (few) lines. Potentially selecting the relevant variables to standardize.
Also, it would be good if the function was able to detect dummies (x2) and avoid standardizing those
I thank you in advance for your help