I have data with a sender and receiver, and number of emails sent. A toy example:
senders <- c("Mable","Beth", "Beth","Susan","Susan")
receivers <- c("Beth", "Mable", "Susan", "Mable","Beth")
num_email <- c(1,1,2,1,1)
df <- data.frame(senders, receivers, num_email)
senders receivers num_email
Mable Beth 1
Beth Mable 1
Beth Susan 2
Susan Mable 1
Susan Beth 1
I'd like to get a data.frame that has the total messages for each unique pair. E.g. the connection Mable | Beth would have value 2, because Mable sent Beth one message, and Beth sent Mable one message. The resulting data.frame should have only one row for each unique combination of emailers (e.g. there would only be Mable | Beth or Beth | Mable, not both.
I've tried various approaches with reshape and data.table, but I'm not having any luck. I'd like to avoid creating a unique string BethMable and merging that way. Many thanks