简体   繁体   中英

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.

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):

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. They both provide a vector that you can use the length() function on

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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