简体   繁体   English

如何计算R中igraph对象中给定类的顶点数?

[英]How do you count the number of vertices of a given class in an igraph object in R?

I'm working with a bipartite multilayer network in the igraph package for R. 我正在igraph软件包中为R使用双向多层网络。

Is there a way to count the number of vertices of a given class and the number of edges on a given layer? 有没有一种方法可以计算给定类的顶点数和给定层上的边数?

The summary function gives me total counts and lists. 摘要功能提供了总数和清单。

Here are the attributes of my network: 这是我的网络的属性:

IGRAPH 3e83b45 UNWB 501 1120 -- + attr: name (v/c), taxon (v/c), taxon.label (v/n), species.size (v/n), type (v/c), weight (e/n), type (e/c) + edges from 3e83b45 (vertex names): IGRAPH 3e83b45 UNWB 501 1120-+属性:名称(v / c),分类单元(v / c),分类单元标签(v / n),种类大小(v / n),类型(v / c),重量(e / n),键入(e / c)+ 3e83b45中的边(顶点名称):

Vertex classes are coded as "taxon", layers (ie, edge types) are coded as "type". 顶点类被编码为“分类单元”,层(即,边缘类型)被编码为“类型”。

Thank you very much! 非常感谢你!

It'd be nice if you provided a minimal reproducible example, but I think simply querying the vertices with V() and querying the edges with E() will get you what you want. 如果您提供了一个最小的可复制示例,那就太好了,但是我认为,简单地使用V()查询顶点并使用E()查询边缘将为您提供所需的结果。 They both provide a vector that you can use the length() function on 它们都提供了一个向量,您可以在其中使用length()函数

library(igraph)

g <- make_graph('zachary') %>%
  set_edge_attr(., 'type', value = sample(c('parent', 'child'),
                                          size = ecount(.), 
                                          replace = T)) %>%
  set_vertex_attr(., 'taxon', value = sample(c('species', 'family', 'class'), 
                                             size = vcount(.), 
                                             replace = T))

V(g)[taxon == 'species']
E(g)[type == 'parent']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM