答案 0 :(得分:4)
假设有这个图:
library(igraph)
g <- graph.empty(n=7,directed=FALSE)
g <- add.edges(g, c(1,2,1,3,1,4,3,5,3,4,4,5,2,7,2,6))
g <- set.vertex.attribute(g, name='vert.names',index=V(g),value=LETTERS[V(g)])
你可以这样得到k-core子图:
coreness <- graph.coreness(g)
maxCoreness <- max(coreness)
# if you just need to know the vertices and not to build the subgraph
# you can use this variable
verticesHavingMaxCoreness <- which(coreness == maxCoreness)
kcore <- induced.subgraph(graph=g,vids=verticesHavingMaxCoreness)
plot(kcore,
vertex.label=get.vertex.attribute(kcore,name='vert.names',index=V(kcore)))
答案 1 :(得分:1)
我用这个链接想出了这个
https://stackoverflow.com/a/3692710/80353
基本上我这样做。
cores = graph.coreness(as.undirected(g))
head(sort(cores, decreasing=TRUE), 3)
这将给出载体中3个最高k核心值。