Finding the median distance between each vertex and its ten nerest neighbors with a igraph object in R

Sunday, May 11, 2014

I have an igraph object (a knn graph) which I created as such:



mygraph <- nng(sim_matrix, k=10)


This give me a nice list of vertices and their ten closest neighbors, a small sample follows:



1 -> 25 26 28 30 32 144 146 151 177 183 2 -> 4 8 32 33 145 146 154 156 186 199
3 -> 1 25 28 51 54 106 144 151 177 234 4 -> 7 8 89 95 97 158 160 170 186 204
5 -> 9 11 17 19 21 112 119 138 145 158 6 -> 10 12 14 18 20 22 147 148 157 194
7 -> 4 13 123 132 135 142 160 170 173 174 8 -> 4 7 89 90 95 97 158 160 186 204


So far so good.


What I'm struggling with, however, is how to to get access to the values for the weight between the vertices that I can do meaningful calculations on.


Say, for example, I want to find the median distance between each vertex and its ten nearest neighbors. Shouldn't be so hard, considering I have the information about who the nearest neighbors are, right?


Looking at the documentation, I tried:



degree(mygraph)


which gives me the sum of the weights for each node. But I don't want the sum, I want the median distance.


I further have attempted to get some sort of matrix out of the graph object, that I can work with, but no luck.


If anyone has any ideas on how to go about approaching this, I'd be grateful. Thanks.







http://ift.tt/1szIMGZ