I tried to do this:
DT <- data.table(Monthname = month.name, id = 1:3, a = abs(rnorm(12)), b = abs(rnorm(12)), c = abs(rnorm(12)), d = abs(rnorm(12)))
setkey(DT, id)
ANS <- DT[,lapply(.SD, mean)/lapply(.SD, sd), by = 'id', .SDcols = names(DT)[-1]]
but it gives error. So, Are there any ways to do this ? Thank You.
myfun <- function(x) mean(x)/sd(x)and then useDT[, lapply(.SD, myfun), by = "id", .SDcols = names(DT)[-1]].