'For cycle for Z score standardization

i'm a beginner in R. I would create a for cycle to standardize my variables. I have a df with 8 columns. This is my code

df_Z=df[,2:9]
for (i in df_Z) {
  dfprova=(df_Z[,i] - mean(df_Z[,i])) / sd(df_Z[,i])
}

The error is shown below :

Error: Must subset columns with a valid subscript vector.
x Can't convert from <double> to <integer> due to loss of precision.
Run `rlang::last_error()` to see where the error occurred.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source