O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating subgraphs

You can create new graphs by selecting the vertices you are interested in, using the following code:

> g.sub <- induced.subgraph(g, c(5, 10, 13, 14, 17, 11, 7)) 

You can also create new graphs by selecting the edges you are interested in, using the following code:

> E(dg) 
 
Edge sequence: 
              
[1]  1  -> 2  
[2]  1  -> 12 
[3]  1  -> 6  
[4]  2  -> 7  
[5]  3  -> 9  
[6]  4  -> 9  
[7]  5  -> 13 
[8]  5  -> 11 
[9]  6  -> 11 
[10] 7  -> 11 
[11] 8  -> 11 
[12] 9  -> 11 
[13] 10 -> 14 
[14] 6  -> 15 
[15] 7  -> 15 
[16] 11 -> 15 
[17] 11 -> 16 
[18] 11 -> 17 
[19] 11 -> 18 
 
> eids <- c(1:2, 9:15) 
> dg.sub <- subgraph.edges(dg, eids)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required