2

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)

plot graph

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

Community
  • 1
  • 1
Selrac
  • 2,203
  • 9
  • 41
  • 84
  • 1
    You could improve your question. Please read [how to provide minimal reproducible examples in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). Then edit & improve it accordingly. A good post usually provides minimal input data, the desired output data & code tries - all copy-paste-run'able in a new/clean R session. To your question: `igraph::degree(g, mode = "in")` might help. – lukeA Oct 06 '16 at 10:42
  • Thanks lukeA. I've edited the code to simplify. Thanks also for your code suggestion. I don' see thought how to get the ones with the most connections though :-( – Selrac Oct 06 '16 at 11:13

1 Answers1

4

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
lukeA
  • 53,097
  • 5
  • 97
  • 100