简体   繁体   中英

Count the nodes with most connection in a network in R igraph

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

For example in a network like this:

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

We would have 3 independent components

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

plot(g)

绘图图

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.

I tried also:

 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")

Any ideas?

Thanks

You could do

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM