Extract row corresponding to minimum value of a variable by group
Slightly more elegant: library(data.table) DT[ , .SD[which.min(Employees)], by = State] State Company Employees 1: AK D 24 2: RI E 19 Slighly less elegant than using .SD, but a bit faster (for data with many groups): DT[DT[ , .I[which.min(Employees)], by = State]$V1] Also, just replace the expression which.min(Employees) with Employees == min(Employees), if your data … Read more