How to apply same function to every specified column in a data.table

后端 未结 7 2318
北海茫月
北海茫月 2020-11-22 08:00

I have a data.table with which I\'d like to perform the same operation on certain columns. The names of these columns are given in a character vector. In this particular ex

7条回答
  •  时光取名叫无心
    2020-11-22 08:44

    None of above solutions seems to work with calculation by group. Following is the best I got:

    for(col in cols)
    {
        DT[, (col) := scale(.SD[[col]], center = TRUE, scale = TRUE), g]
    }
    

提交回复
热议问题