I am an R newbie, and I would like to divide every value in the 168 columns of my dataset by the SD of the respective column.
I tried:
new<- for (i in 1:168 (df))
function(x){
x/sd(x, na.rm=TRUE)
}
}
But it didn't work. It is the first time I am working with loops or functions. Therefore, I would be happy for your help. This is an example from my dataset (3columns). There are 168 columns, and the 169th column has the IDs.
structure(list(var1 = c(1, 2, 35, 5, 22, 26.5, 31, 35.5, 40,
44.5, 49, 53.5, 58, 62.5, 67, 71.5, 76, 80.5, 85), var2 = c(1,
2, 4, 5.33333333333333, 6.83333333333333, 8.33333333333333, 9.83333333333333,
11.3333333333333, 12.8333333333333, 14.3333333333333, 15.8333333333333,
17.3333333333333, 18.8333333333333, 20.3333333333333, 21.8333333333333,
23.3333333333333, 24.8333333333333, 26.3333333333333, 27.8333333333333
), var3 = c(2, 1, 3, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5,
8, 8.5, 9, 9.5, 10, 10.5)), row.names = c(NA, -19L), class = c("tbl_df",
"tbl", "data.frame"))
Thanks, Caro