问题 In R data.table it is possible and easy to aggregate on multiple columns using argmin or argmax functions in one aggregate. For example for DT: > DT = data.table(id=c(1,1,1,2,2,2,2,3,3,3), col1=c(1,3,5,2,5,3,6,3,67,7), col2=c(4,6,8,3,65,3,5,4,4,7), col3=c(34,64,53,5,6,2,4,6,4,67)) > DT id col1 col2 col3 1: 1 1 4 34 2: 1 3 6 64 3: 1 5 8 53 4: 2 2 3 5 5: 2 5 65 6 6: 2 3 3 2 7: 2 6 5 4 8: 3 3 4 6 9: 3 67 4 4 10: 3 7 7 67 > DT_agg = DT[, .(agg1 = col1[which.max(col2)] , agg2 = col2[which.min(col3