Looking to create a function.
I would like to add the number of occurrences of an observation up within a given group (ex 5, 5 occurrences 2 times). The same numbers of Days within a Week by Business are to be summed. The summed values will be in a new row 'Total-occurrences.'
tapply or plyr works its way into this, however I'm stuck on a few nuances.
Thanks!
14X3 matrix
Business Week Days
A **1** 3
A **1** 3
A **1** 1
A 2 4
A 2 1
A 2 1
A 2 6
A 2 1
B **1** 1
B **1** 2
B **1** 7
B 2 2
B 2 2
B 2 na
**AND BECOME**
10X4 matrix
Business Week Days Total-Occurrences
A **1** 3 2
A **1** 1 1
A 2 1 3
A 2 4 1
A 2 6 1
B **1** 1 1
B **1** 2 1
B **1** 7 1
B 3 2 2
B 2 na 0