我正在尝试使用ddply
(一个plyr
函数)从以下形式的社交媒体数据中对任何唯一用户对之间最频繁的交互类型进行排序和识别
from <- c('A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'D')
to <- c('B', 'B', 'D', 'A', 'C', 'C', 'D', 'A', 'D', 'B', 'A', 'B', 'B', 'A', 'C')
interaction_type <- c('like', 'comment', 'share', 'like', 'like', 'like', 'comment', 'like', 'like', 'share', 'like', 'comment', 'like', 'share', 'like')
dat <- data.frame(from, to, interaction_type)
如果聚合正确,应该找到任何唯一对之间最常见的交互类型(无论方向性如何(即 A-->B,A<--B)),就像这样
from to type
A B like
A C like
A D share
B C like
B D comment
C D like
虽然通过使用很容易获得任意两个用户之间的交互总数
count <- ddply(sub_test, .(from, to), nrow)
我发现很难应用类似的方法来找到使用这种聚合方法的任何给定对之间最常见的交互类型。实现我想要的输出的最有效方法是什么?另外,如何处理可能的“捆绑”案件?(我可能只使用“tided”作为所有已绑定案例的单元格值)。