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

How to do it...

To compute important network metrics, follow these steps:

  1. Load the data files:
> load("undirected-graph.Rdata") 
> load("directed-graph.Rdata") 
> load("bipartite-graph.Rdata")
  1. The degree centrality can be measured as follows:
> degree(dg) 
 
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 
 3  2  1  1  2  3  3  1  3  1  9  1  1  1  3  1  1  1 
 
> degree(g) 
 
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 
 3  2  1  1  2  3  3  1  3  1  9  1  1  1  3  1  1  1 
 
> degree(dg, "7")    
 
7  
3  
 
> degree(dg, 9, mode = "in") 
 
9  
2  
 
> degree(dg, 9, mode = "out") 
 
9  
1 
 
> # Proportion of vertices with degree 0, 1, 2, etc. 
> options(digits=3) 
> degree.distribution(bg) 
 
[1] 0.0714 0.2857 0.1429 0.3571  
[5] 0.0714 0.0000 0.0000 0.0714 
  1. The betweenness centrality can be measured as follows:
> betweenness(dg) ...

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