我有以下数据集:
library(data.table)
dt1 <- data.table(Activity1 = c("A","A","B","B","C","C"),
Activity2 = c("B","C","A","C","A","B"),
participants = c(12, 22, 4, 20, 3, 31))
# OUTPUT (dt1)
# Activity1 Activity2 participants
# 1: A B 12
# 2: A C 22
# 3: B A 4
# 4: B C 20
# 5: C A 3
# 6: C B 31
我试图找到Activity1和Activity2的所有独特组合,这样我最终会得到一个如下所示的数据集(总结潜在的参与者):
# DESIRED Dataset
# Activity1 Activity2 participants
# 1: A B 16
# 2: A C 25
# 4: B C 51
我对R来说还是比较新的,并且会感激任何指导。 提前谢谢。