1

I have a directed graph (grafopri1fase1) the graph has no loops and it has a tree structure (not binary tree). I have an array of nodes (meterdiretti) that i have extracted from the graph (grafopri1fase1) matching a condition.

I would like to know starting from each node of Meterdiretti how many nodes are under each node of Meterdiretti.

The result I would like to have is a Matrix with the following format

first column------------     second column       
meterdiretti[1] -------- total amount of nodes reachable starting from meterdiretti[1] 

meterdiretti[2] -------- total amount of nodes reachable starting from meterdiretti[2] 

.... 

meterdiretti[n]  ----------total amount of nodes reachable starting from meterdiretti[n]
user20650
  • 24,654
  • 5
  • 56
  • 91
Alex Fort
  • 93
  • 6

1 Answers1

1

Take a punt at what you want - it would be good if you could add a reproducible example to your question.

I think what you want is to count the descendents of a node. You can do this with neighborhood.size and mode="out" argument.

library(igraph)

# create a random graph
g <- graph.tree(17, children = 2)
plot(g, layout=layout.reingold.tilford)

# test on a single node    
neighborhood.size( g, vcount(g),  "1", "out") - 1
# [1] 16

# apply over a few nodes
neighborhood.size( g, vcount(g),  c(1,4,7), "out") - 1
[1] 16  4  2

enter image description here

user20650
  • 24,654
  • 5
  • 56
  • 91
  • You're right about putting an example in it, but the site does not allow me to insert any picture because I have not enough credits. – Alex Fort Jan 16 '15 at 09:15
  • Hi Alex, glad it worked for you. For future, maybe good to have a look at [this](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) which gives details on making an example. Also have a wee look at other questions to see how how to create minimum working examples - like answer above. if you need to add an image you can save it in an external hosting site and add a link - someone will add it to your question. These things just make it easier for you to get a good answer. atb – user20650 Jan 16 '15 at 13:44