I've got a data frame with two columns: name and action_id. Names often have multiple action_ids, and action_ids are also associated with multiple names, like so:
name action_id
Bob 1
Bob 2
Bob 3
Tom 2
Tom 1
Bill 1
Bill 3
Here's my problem: I'm trying to index the overlap between the action_ids based on the names. So if a name is associated with two action_ids, and another name is associated with the same two action_ids, the overlap between those two action_ids is 1. For the data above, this function would return an overlap of 1 between action_ids 1 and 2, 1 between 1 and 3, and 0 for other potential overlaps. I'm picturing a data table with all potential action_id overlaps and the instances of those overlaps, like so:
1 2 3
1 - 0 0
2 1 - 0
3 1 0 -
I've tried to tackle this by converting the data frame to a data table that indexes all action_ids associated with users, but am having trouble then converting that data table into an action_id-only table as shown above.
I thought of looping through all the data, but I'm dealing with millions of rows -- for/if loops aren't time-efficient enough here, so I'm trying to find a vector-based solution.