我正在尝试将中心性度量作为属性添加到“主图”g_master。这是我的代码:
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)
但我得到以下信息:
> 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
代码的其他部分很好。