[英]Counting total number of other edges an edge is connected to in R?
I'd like to find a way to count the total number of other edge ends the primary edge is attached to for all edges in a network and set as an attribute for each edge in R using igraph (or any other package) 我想找到一种方法来计算网络中所有边缘主要边缘连接到的其他边缘末端的总数,并使用igraph(或任何其他包)将其设置为R中每个边缘的属性
I understand the igraph package has a variety of tools that may get the job done. 我了解igraph软件包中有多种工具可以完成工作。 Being new to the package, I'm not certain which combination of functions will give me the desired output.
作为软件包的新手,我不确定哪种功能组合可以提供所需的输出。
I guess the workflow would look something like the following 我猜工作流程如下所示
get the graph 得到图
g <- sample_gnp(10, 1/10)
set vertex attribute equal to degree 将顶点属性设置为等于度
g %>% set_vertex_attr("deg", value = degree(g))
# of course, this doesn't work. So sorry, I'm new to igraph
write a function to execute the following 编写一个函数来执行以下操作
edge attribute = (total sum of the degree of connected vertices) - (the number of connected vertices)
Any help would be appreciated 任何帮助,将不胜感激
You could set the vertex attribute with 您可以使用设置顶点属性
degrees <- degree(gr)
gr <- set_vertex_attr(gr, name="degr", value=degrees)
and calculate the second task maybe like this 然后计算第二个任务
sum(degrees) - sum(degree > 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.