Assume I have a dataframe:
Col1 Col2 Col3 Val
a 1 a 2
a 1 a 3
a 1 b 5
b 1 a 10
b 1 a 20
b 1 a 25
I want to aggregate across all columns and then attach this to my dataframe so that I have this output:
Col1 Col2 Col3 Val Tot
a 1 a 2 10
a 1 a 3 10
a 1 b 5 10
b 1 a 10 55
b 1 a 20 55
b 1 a 25 55
Is there something I can do with tapply
to accomplish this? I'm a little stuck on the most efficient way.