I am trying to remove duplicate rows from a data frame based on the max value on a different column
So, for the data frame:
df<-data.frame (rbind(
One possible way is to use data.table
data.table
library(data.table) setDT(df)[, .SD[which.max(val2)], by = id] ## id val1 val2 ## 1: a 3 5 ## 2: b 2 6 ## 3: r 4 5