streak_run() computes the running length of consecutive elements, making it useful for tracking streaks within grouped sequential data. In a free-throw analysis, group_by(date) keeps one game from carrying a streak into the next; mutate(streak = streak_run(lag(points))) calculates the streak from the previous points value. section 16.4.1
Tracking free-throw streaks
For Giannis Antetokounmpo’s free throws, streak equals 0 when the date changes and equals 1 after the first attempt. Subsequent values increase across consecutive outcomes. Filtering records where lag(points) == 1 and summarizing makes and misses by streak produces shooting percentages after one or more consecutive makes. section 16.4.1
