Get node descendants in a tree graph

霸气de小男生 提交于 2019-12-08 05:22:53

问题


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]

回答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



来源:https://stackoverflow.com/questions/27968678/get-node-descendants-in-a-tree-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!