我找到關於如何使用graph.coreness
的文檔here。如何使用graph.coreness找到頂點所屬的最大k-core
不幸的是,我找回了大約27000個條目的數字列表。
我的目的是簡單地找出如何找出條目所屬的最大k-核心。
我該怎麼做?
我找到關於如何使用graph.coreness
的文檔here。如何使用graph.coreness找到頂點所屬的最大k-core
不幸的是,我找回了大約27000個條目的數字列表。
我的目的是簡單地找出如何找出條目所屬的最大k-核心。
我該怎麼做?
我想通了這一點通過此鏈接
https://stackoverflow.com/a/3692710/80353
我基本上做到這一點。
cores = graph.coreness(as.undirected(g))
head(sort(cores, decreasing=TRUE), 3)
這會給我3個最高的k-核心值在向量中。
假如有這樣的圖形:
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-核子以這樣的方式
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)))
改進了頂點標籤的例子。 – digEmAll
嗚!真棒回答!〜想像我一樣 –
發佈本作評論,因爲我不確定這是否是你需要的,但我想'which.ma x(表(graph.coreness(g)))'應該做的。對? – nico
試過了。這給了我最大的頂點,但不是頂點所屬的最大的k-核心。 –