-1

I have a 3 column data which looks like below:

RowID callerid item_id contributor
28476 919471180334 1014038 911111111111
28477 919471180334 1026448 919939727689
28478 919471180334 1026334 918002321300
28479 919471180334 1026177 911111111111
28480 919471180334 1026063 919934520183
28481 919471180334 1026155 919939727689

There are hundreds of records. I need to find the reciprocity among the element of column caller id and contributor id. It means how many cases a callerID listened to item posted by contributor and vice versa. is there any direct function that can be useful in this case?

  • 2
    Does this answer your question? [count unique combinations of values](https://stackoverflow.com/questions/8862105/count-unique-combinations-of-values) – Felix Phl Nov 02 '20 at 17:45

2 Answers2

0

Is this what you're looking for:

dat <- tibble::tribble(
~RowID,  ~callerid, ~item_id, ~contributor,
28476, 919471180334, 1014038, 911111111111,
28477, 919471180334, 1026448, 919939727689,
28478, 919471180334, 1026334, 918002321300,
28479, 919471180334, 1026177, 911111111111,
28480, 919471180334, 1026063, 919934520183,
28481, 919471180334, 1026155, 919939727689)


dat %>% group_by(callerid, contributor) %>%  summarise(n=n())
# `summarise()` regrouping output by 'callerid' (override with `.groups` argument)
# # A tibble: 4 x 3
# # Groups:   callerid [1]
#       callerid  contributor     n
#          <dbl>        <dbl> <int>
# 1 919471180334 911111111111     2
# 2 919471180334 918002321300     1
# 3 919471180334 919934520183     1
# 4 919471180334 919939727689     2
DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
0
df <- data.frame(item_id = rep(919471180334, 6),
           contributor = c(911111111111,919939727689,918002321300,911111111111,919934520183,919939727689))

A base R solution:

as.data.frame(table(df))

   item_id  contributor Freq
1 919471180334 911111111111    2
2 919471180334 918002321300    1
3 919471180334 919934520183    1
4 919471180334 919939727689    2

or with plyr

plyr::count(df)

       item_id  contributor freq
1 919471180334 911111111111    2
2 919471180334 918002321300    1
3 919471180334 919934520183    1
4 919471180334 919939727689    2

Difference is, that plyr::count does not include combinations with zero counts, which makes no difference for your case.

Felix Phl
  • 383
  • 1
  • 13