我的
data
下面有两列(
studyID
&
post_id
). 该列
post_id
具有4个唯一值(
1 2 3 4
).
我想知道如何确定的每个唯一值的次数
post_id
(例如。,
1
)与的另一个唯一值同时出现
post_id
(例如。,
2
)在每个级别中
studyID
?
对于此数据,预期输出应该是一个具有
下列的
6个独特元素
[row,col]
在其上
下三角形
和
NA
其他任何地方。
这可能在中实现吗
R
?
跨越所有级别
studyID
,
1.
具有
2.
共发生31次。
[2,1]
跨越所有级别
studyID
,
1.
具有
3
共发生3次。
[3,1]
跨越所有级别
studyID
,
1.
具有
4
共发生1次。
[4,1]
跨越所有级别
studyID
,
2.
具有
3.
共发生3次。
[3,2]
跨越所有级别
studyID
,
2.
具有
4.
共发生1次。
[4,2]
跨越所有级别
studyID
,
3.
具有
4.
共发生1次。
[4,3]
data <- read.csv("https://raw.githubusercontent.com/ilzl/i/master/pr.csv")[c(1,7)]