Trying to apply the common measures of centrality to a simple data set of non-directed like this:
It gives error:
Error in closeness(net, gmode = "graph") : unused argument (gmode = "graph")
When I removed the argument (gmode = "graph), it gives:
Error in degree(W) : Not a graph object
I have tried to use this lines to convert them, but still doesn't work:
W <- graph_from_adjacency_matrix(df)
W <- graph_from_data_frame(df)
How can I correct them? thank you.
Here are the lines:
Bob <- c(0,1,0,0,0)
Kate <- c(0,0,0,1,0)
David <- c(0,0,0,1,0)
Jack <- c(0,0,1,0,0)
Peter <- c(0,1,0,0,1)
df <- data.frame(Bob, Kate, David, Jack, Peter)
library(igraph)
W <- data.frame(df)
net <- network(W)
net %v% 'vertex.names'
degree(W, gmode="graph")
closeness(net, gmode="graph")
betweenness(net, gmode="graph")
Add-on after this question is answered, in case it can help someone - to convert Excel format into a adjacency_matrix, use below lines.
df <- readxl::read_excel("spreadsheet.xlsx", sheet = "Sheet1")
W <- as.matrix(df)
W <- graph_from_adjacency_matrix(W)