I have a table that looks like this
uid gid score
1 a 5
1 a 8
1 a 9
1 b 2
1 b 7
2 a 5
2 a 9
.
.
.
But with many more entries for each user and group.
I want to get a table that has a row for each uid/gid pairing that is the mean of their bottom 5 scores.
This was trivial in Excel using pivot tables, but I need to do some analysis that R is much better for.
So I want my result to look like
uid gid top5avg
1 a 4.3
1 b 5.7
2 a 3.5
2 b 6.8
.
.
.
with one row for each uid gid pair and then the average of the top five scores for that uid/gid pair.
If your data was called dat this would work:
EDIT:
If you meant the opposite (bottom 5) than what I had, as indicated by Joran (I was confused too), then use
revas in:Or use the
tailsuggestion Joran made.