This question is in continuation with this one which I asked here:
Now I have data something like this:
Sno User Cookie
1 1 A
2 1 A
3 1 A
4 1 B
5 1 C
6 1 D
7 1 A
8 1 B
9 1 D
10 1 E
11 1 D
12 1 A
13 2 F
14 2 G
15 2 F
16 2 G
17 2 H
18 2 H
So lets say we have 5 cookies for user 1 'A,B,C,D,E'. Now I want to count if any cookie has reoccurred after a new cookie was encountered. For example, in the above example, cookie A was encountered again at 7th place and then at 12th place also. NOTE We wouldn't count A at 2nd place as it came simultaneously, but at position 7th and 12th we had seen many new cookies before seeing A again, hence we count that instance. So this is what I will get if I run code mentioned in my previous post:
For User 1
Sno Cookie Count
1 A 2
2 B 1
3 C 0
4 D 2
5 E 0
For User 2
Sno Cookie Count
6 F 1
7 G 1
8 H 0
Now comes the tricky part, now we know by the count, that for user 1, three cookies "A, B and D" re-occurred. Similarly for User 2 "F and G" reoccurred. I want to aggregate these results like this:
Sno User Reoccurred_Instances
1 1 3
2 2 2
Is there any easier way without using a loop to get this result.