replace tapply to data.table, faster solution