Basic R

R
POL 491
Network Analysis

Basic R

Matrices in R

One basic format for network data is the matrix. You can make basic matrices using the matrix() function:

mat <- matrix(c(0, 1, 0, 0, 0, 0, 1, 1, 0), nrow = 3, ncol = 3, byrow = T)
mat
     [,1] [,2] [,3]
[1,]    0    1    0
[2,]    0    0    0
[3,]    1    1    0

Adding Names

The rownames() and colnames() functions are used access or set the row names and column names.

rownames(mat) <- c("JoJo", "Frida", "Kevin ")
colnames(mat) <- rownames(mat)
mat
       JoJo Frida Kevin 
JoJo      0     1      0
Frida     0     0      0
Kevin     1     1      0