Skip to main content
2 of 2
added 10 characters in body
Kuba
  • 137.7k
  • 13
  • 289
  • 751

Counting subsequences (i.e., patterns) within a list?

I would like to count the number of subsequences in list. Say I have data given by:

data = {1, 1, 1, 2, 1, 2, 2, 2, 1, 2, 1};

I would like to count the number times I see the following subsequences: {1,1}, {1,2}, {2,1}, {2,2}. Is there a quick way to do so? I've tried a few approaches using Count and Cases with no luck. Any advice would be greatly appreciated.

Thanks!