Creating an iGraph Subgraph

I have the following problem:
I have the following graph: g6 , which does not include isolate vertices . The vertices are mainly grouped into two ethnic groups defined as an attribute, namely: mestizo and saraguro .
Therefore, I run the subgraph parameter for saraguros as follows:

g2saraguro & ltg - subgraph (g6, which (V (g6) $ ethnic == "saraguro"))
resume (g2saraguro)

which worked:

Vertices: 166
Edges: 330
Director: TRUE
No graph attributes.
Attributes of the peaks: ii, village, parroquia, canton, provinz, kindR, ethnicity, situation, researcha.
Edge Attributes: Question, Activity.

However, if I try to do the same with mestizo , there is a breakthrough, as it simply identifies:

s2mestizo <- subgraph (g6, V (g6) $ ethnic == "mestizo")
Summary (s2mestizo)
Vertices: 2
Edges: 3
Director: TRUE
No graph attributes.
Attributes of the peaks: ii, village, parroquia, canton, provinz, kindR, ethnicity, situation, researcha.
Edge Attributes: Question, Activity.

but in reality this is not so, if I see: V(g6)$ethnic , mestizo - most !!
I really don’t know where the problem is: igraph 0.6 the subgraph formation procedure should be in one form or another, without 1-based indexing .
Thanks so much for any help
Yours faithfully
Vladimir

+4
source share
1 answer

You forgot to use the which function in the second case; i.e. instead of

 s2mestizo <- subgraph(g6,V(g6)$ethnic=="mestizo") 

you should write

 s2mestizo <- subgraph(g6, which(V(g6)$ethnic=="mestizo")) 

Also note that if you use igraph 0.5.x or earlier, you must subtract 1 from the result of which due to indexing of igraph based on 0. This has been fixed in igraph 0.6, so you do not need to subtract 1 if you use igraph 0.6 or newer.

Edit : based on your recent comment, it looks like you are using igraph 0.5.x or earlier (because the output format of summary differs by 0.6). In this case, you must subtract 1 from the result of which , because igraph 0.5.x and earlier versions use zero vertex indices. Therefore, the correct line should be:

 s2mestizo <- subgraph(g6, which(V(g6)$ethnic=="mestizo")-1) 
+3
source

Source: https://habr.com/ru/post/1433568/


All Articles