I have a dataframe that contains information about financial contributions to political candidates (denoted in the data by "cand") and political organizations (denoted in the data by "comm"). The dataframe also includes a unique ID for each contributor, with each row in the data denoting one contribution made. What I want to do is get a crosstab that shows, for each political (non-candidate) organization, how many donors to those organizations also contributed to each political candidate in the dataframe. The dataframe looks like this:
contributor ID . organization
1 cand1
2 cand2
3 comm1
3 cand1
4 cand1
5 cand2
5 cand1
5 comm2
What I want to be able to create is something like this:
Comm . Cand
Cand1 . Cand2
Comm1 1 0
Comm2 1 1
(Because 1 person -- ID #3 -- contributed to both comm1 and cand1, and 1 person -- ID #5 -- contributed to comm1, cand1, and cand2.)
I have thought about ways to do this using aggregate or dplyr, but I'm not sure. Does anyone have any tips?