Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中的有向网络中查找匹配项_R_Datatable_Match_Igraph_Reshape2 - Fatal编程技术网

在R中的有向网络中查找匹配项

在R中的有向网络中查找匹配项,r,datatable,match,igraph,reshape2,R,Datatable,Match,Igraph,Reshape2,我正在研究一个使用iGraph的定向数据集,该数据集基于在Twitter上相互关注的人。我有一个数据表 follower_user_id | followed_user_id | gender_of_follower | gender_of_followed 1 | 2 | F | M 2 | 3 |

我正在研究一个使用iGraph的定向数据集,该数据集基于在Twitter上相互关注的人。我有一个数据表

follower_user_id | followed_user_id | gender_of_follower | gender_of_followed
               1 |                2 |                 F  |                  M 
               2 |                3 |                 M  |                  M
               3 |                2 |                 M  |                  M 
等等

我想评估匹配情况,用户在哪些情况下相互跟踪,以便我可以进一步了解谁没有被跟踪,例如男性是否比女性更可能被跟踪(等等)。但我不知道首先如何筛选比赛

到目前为止,我认为最好的方法是使用一个包含所有用户ID和所有用户ID的矩阵,并计算每一对出现在一起的时间

M <- table (df$follower_user_id, df$followed_user_id)
follower.followed.matrix <- M %*% t(M)


XXXXX 1    2   3 
1     0    1   0
2     0    0   1
3     0    1   0 

M获取所需矩阵-邻接矩阵-内置于igraph中。我将使用一个比您稍大的示例来确保解决方案能够处理所有情况

数据:扩大的跟随者网络 现在,通过邻接矩阵,你可以快速计算A跟在B后面,B跟在A后面的对

sapply(1:5, function(x) { AM[x,] * AM[,x] })
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    0    0    1    1    0
[3,]    0    1    0    0    0
[4,]    0    1    0    0    0
[5,]    0    0    0    0    0
您可以看到所需的对是(2,3)、(2,4)、(3,2)和(4,2)

sapply(1:5, function(x) { AM[x,] * AM[,x] })
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    0    0    1    1    0
[3,]    0    1    0    0    0
[4,]    0    1    0    0    0
[5,]    0    0    0    0    0