How do I first sort and then select the first row by group with data.table?
Originally the procedure was implement using dplry
dat_dplyr <- dat %>% group_by(V1, V2) %>% arrange(V1, V2, desc(V3), desc(V4)) %>% filter(row_number() == 1)
This works, but a bit slow. So what would be the data.table equivalent? Would it be
DT <- as.data.table(dat)
test <- DT[order(-V3,-V4), .SD[1], by = .(V1, V2)]
Thanks very much for your help!