Subset by group with data.table
问题 Assume I have a data table containing some baseball players: library(plyr) library(data.table) bdt <- as.data.table(baseball) For each player (given by id), I want to find the row corresponding to the year in which they played the most games. This is straightforward in plyr: ddply(baseball, "id", subset, g == max(g)) What's the equivalent code for data.table? I tried: setkey(bdt, "id") bdt[g == max(g)] # only one row bdt[g == max(g), by = id] # Error: 'by' or 'keyby' is supplied but not j bdt