Reputation: 93
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]
Upvotes: 1
Views: 1353
Reputation: 25854
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
Upvotes: 1