aggregate(df$count, list(df$sport, df$color), sum)
Aggregate returns the below data frame, but I just want to return the maximum count for each color:
Sport Color Count
Baseball Blue 5
Football Blue 10
Basketball Blue 7
Baseball Red 6
Football Red 9
Basketball Red 13
I would want the code to return:
Sport Color Count
Football Blue 10
Basketball Red 13
Because Football has the highest count in blue group and basketball has highest count in red group.