O'Reilly logo

Practical Data Science Cookbook - Second Edition by Abhijit Dasgupta, Benjamin Bengfort, Sean Patrick Murphy, Tony Ojeda, Prabhanjan Tattar

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...

  1. The first task is to load the required libraries:
library(statnet,quietly=TRUE)library(network,quietly=TRUE)  

The purpose of specifying the option quietly=TRUE is that a lot of comments are printed to the console and we can offset that with this option. Operationally, it makes no difference whether we use this option or not.

  1. Next, we specify a matrix with four rows and columns, a square matrix as expected, which will be then used to set up a network:
netmat1 <- rbind(c(0,1,1,0),                 c(1,0,1,0),                 c(1,1,0,1),                 c(0,0,1,0))rownames(netmat1) <- c("A","B","C","D")colnames(netmat1) <- c("A","B","C","D")netmat1  
  1. A consequence is the following output in the R console:
> netmat1A B C DA 0 1 1 0B 1 0 1 0C 1 1 0 1D 0 0 1 0
  1. The matrix ...

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