ofrendo
6/7/2017 - 12:42 PM

data.table operation on subset of column grouped by other column, column wise

data.table operation on subset of column grouped by other column, column wise

# cols_to_scale is a character vector of columns
tmp[, 
      (cols_to_scale) := lapply(.SD, function(col) {
       print(NROW(col))
       scale(col)[,1]
     }), 
     .SDcols = cols_to_scale,
     by = LINE]