r - 在 R igraph 中统计网络中连接最多的节点

标签 r igraph

我想统计单向网络中接收连接数较多的节点数量。

例如在这样的网络中:

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

我们将有 3 个独立的组件

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

plot(g)

plot graph

如何获取连接数较多的目标节点?在本例中为节点 7 和 8。

在另一个问题( r igraph most connected nodes )之后,我尝试了以下操作:

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 

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

我也尝试过:

 sort(g, decreasing = TRUE)

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

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

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

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

关于r - 在 R igraph 中统计网络中连接最多的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39893798/

相关文章:

r - 在 data.table 中插入一行

networking - R 中的巨型组件

r - 将数据帧与 data.table 匹配

python - numpy 中的 cbind(R 函数)等价物

c++ - Netbeans 无法识别 igraph 函数

python-igraph : cannot decompose directed graph (neither STRONG nor WEAK)

r - 在循环中覆盖 "Non-Existent Components"

python - 基于顶点名称 Python igraph 执行图的并集

r - 为什么 `as.factor` 在通过 R 中的 `apply` 函数应用时不起作用?

r - 在 R Shiny 中动态调整 ggplot2 图形的大小