在Riggraph中计算网络中连接最多的节点 [英] Count the nodes with most connection in a network in R igraph

查看:109
本文介绍了在Riggraph中计算网络中连接最多的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算单向网络中接收到更多连接的节点数.

I want to count the number nodes with more received connections in a unidirectional network.

例如在这样的网络中:

g <- graph( c('A',1,'A',2,'A',3,'B',4,'B',5,'B',6,'C',7,'C',8,'D',7,'D',8))

我们将有3个独立的组成部分

We would have 3 independent components

将数据加载到文件中(测试),我可以上传并表示如下:

Loading the data in a file (test), I can upload it and represent it as follows:

plot(g)

如何获得具有更多连接的目标节点?在这种情况下,将是节点7和8.

How can I get the destination nodes with more connections? In this case will be node 7 and 8.

接下来的另一个问题(为连接最多的节点),我尝试了以下操作:

Following another question (r igraph most connected nodes) I tried the following:

lengths(as_adj_list(g))

A 1 2 3 B 4 5 6 C 7 8 D 
3 1 1 1 3 1 1 1 2 2 2 2 

结果是计算所有节点的长度,但我只查看目标节点.

The result is counting the lengths of all the nodes, but I'm looking at the destination nodes only.

我也尝试过:

 sort(g, decreasing = TRUE)

 Error in intI(i, n = x@Dim[1], dn[[1]], give.dn = FALSE) : index larger than maximal 12

如您所见,我收到一条错误消息

As you see I get an error message

评论之后:通过以下内容,我可以得到目标节点的数量,但是如何获得具有最大数量的目标节点呢?

Following on commentary: With the following I get the count of the destination nodes, but how do I get the ones with the maximum count?

degree(g4, mode = "in")

有什么想法吗?

谢谢

推荐答案

您可以做到

library(igraph)
g <- graph( c('A',1,'A',2,'A',3,'B',4,'B',5,'B',6,'C',7,'C',8,'D',7,'D',8))
V(g)$indeg <- degree(g, mode = "in")
V(g)[V(g)$indeg == max(V(g)$indeg)]
#  2/12 vertices, named:
# [1] 7 8

这篇关于在Riggraph中计算网络中连接最多的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆