I have a dataframe with a column ("combo") of comma-separated values indicating event-types that co-occur within the same timeperiod. I am looking for a way to count the frequency of pair-wise combinations (order does not matter; i.e., AB and BA are equivalent).
toy dataframe
+------------------------+
|combo startts endts|
| A,B 02:20 02:23 |
| A,B,D 02:23 02:25 |
| A,C 02:27 02:28 |
+------------------------+
Ideal output:
+---------------------------+
|combo | count |
+---------------------------+
| AB | 2 |
| AC | 1 |
| AD | 1 |
| BC | 0 |
| BD | 1 |
| CD | 0 |
+-----------+---------------+
I was thinking of first generating all unique pair-wise combinations, putting that in a column, and then doing a conditional mutate with a regex pattern match; however, I wasn't sure how to refer to the column name abstractly rather than a particular string pattern (or if that is even possible).
Thank you for your time.