Using read_csv() on a matrix to create an adjacency matrix in igraph

369 Views Asked by At

I have a matrix stored as a .csv file, in which column and row headers are identical (it's a citation matrix).

I use read.csv() to read the file and then I apply as.matrix() to transform the df into a matrix. I subsequently transform the matrix into a network with igraph's graph_from_adjacency_matrix().

I cannot do this with readr's read_csv(). When I apply graph_from_adjacency_matrix() to the file read by read_csv() I end up with a non-square matrix which isn't what the function expects.

I think this is because read_csv() produces a tibble in which the very first column is labeled with readr's best guess for a column name (X1). An adjacency matrix does not need the first column in the matrix labeled (I think) and I am stumped about how to remove the first column header from only the very first row.

Can anyone explain how to get around this if I want to use read_csv() rather than read.csv()?

0

There are 0 best solutions below