I have three columns "Name", "success Dummy" and "Date". For each NAME I want to check the PAST SUCCESS for that NAME.
So for example if name "Peter" has occurred three times, for each time I want to count the number of "Peter" with "Success ==1" and Date happened before.
Example of the output that I need to get for "Past Success" column.
Name Success Date Past Success
David 1 2018 1
Peter 0 2017 3
Peter 1 2016 2
David 1 2017 0
Peter 1 2015 1
Peter 0 2010 1
Peter 1 2005 0
Peter NA 2004 0
Is there any way to do it fast?
Also I need it to be very fast because my data is huge.
What I did is I sorted my data based on Names and Dates and check each observation against 100 observations before (because max of frequency of Names is 100).
Please advise if there is a better way to do that.