2

I found the documentation here on how to use graph.coreness.

Unfortunately I get back a list of numbers which was about 27000 entries long.

My purpose is to simply figure out how to find out the largest k-core the entries belong to.

How do I do that?

Vivek Aditya
  • 1,145
  • 17
  • 46
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
  • Posting this as a comment, as I am not really sure whether this is what you need, but I guess `which.max(table(graph.coreness(g)))` should do the trick. Right? – nico Nov 02 '13 at 17:09
  • Tried it. this gives me the largest vertex, but not the largest k-core the vertices belong to. – Kim Stacks Nov 02 '13 at 17:15

2 Answers2

5

Supposing to have this graph :

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)])

graph

You can get the k-core subgraph in this way :

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)))

k-core subgraph

digEmAll
  • 56,430
  • 9
  • 115
  • 140
1

I figured this out using this link

https://stackoverflow.com/a/3692710/80353

Basically I do this.

cores = graph.coreness(as.undirected(g))
head(sort(cores, decreasing=TRUE), 3)

This will give me the 3 highest k-core values in the vector.

Community
  • 1
  • 1
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282