I am trying to add centrality measures as attributes to a "master graph", g_master. Here is my code:
library(igraph)
#generate master graph
g <- sample_pa(10000)
g_in <- degree(g, mode="in")
g_out <- degree(g, mode="out")
g_inclo <- closeness(g, mode="in")
g_outclo <- closeness(g, mode="out")
g_bet <- betweenness(g)
set_vertex_attr(g, "name", index=V(g), value = V(g))
g_master <- data.frame(V(g), g_in, g_out, g_inclo, g_outclo, g_bet)
But I get the following:
> g_master <- data.frame(V(g), g_in, g_out, g_inclo, g_outclo, g_bet)
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ""igraph.vs"" to a data.frame
Other parts of the codes are fine.
As the error says, it faces problems trying to use something of class
igraph.vs. In particular, it isV(g)what causes problems. But we can coerce it as follows: