Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an adjacency list from a data.frame

Tags:

r

igraph

I have a data.frame with 2 columns: Node A, Node B. Each entry in the frame implies an edge in a graph between node A and B.

There must be a nice one-liner to convert this data.frame into an adjacency list. Any hints?

like image 777
Josh Reich Avatar asked Jul 11 '09 21:07

Josh Reich


1 Answers

Since you tagged this igraph, how about using built in functionality?

> g <- graph.data.frame( edges )
> adjlist <- get.adjedgelist(g)

Only caveat is the vertices are zero indexed, which will be changing with igraph 0.6.

like image 115
mindless.panda Avatar answered Sep 21 '22 03:09

mindless.panda