Hello, R experts: I got data like this: group duplicate treatment A Y 5 A Y 3 A N 6 B Y 2 B N 4 B Y 1 How to sort the data and calculate the average treatment value for each group in two level of duplicate. Results like this: group duplicate treatment A Y 4 A N 6 B Y 1.5 B N 4 Thank you in advance. Josh