I want to compute trailing mean GPA by Name from the table below at each index. For example at index 9, I want to have the mean GPA for C from indices 3, 6, 9 and likewise for A and B. At index 6 I want to have the GPA for C from indices 3 and 6. tapply alone won't solve my problem because I want a value for each row.
What's a clean way of doing this ?
Index Name GPA
1 A 5
2 B 6
3 C 7
4 A 5
5 B 6
6 C 6
7 A 7
8 B 6
9 C 3