Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing edge list in igraph in R

I'm trying to import an edge list into igraph's graph object in R. Here's how I'm trying to do so:

graph <- read.graph(edgeListFile, directed=FALSE)

I've used this method before a million times, but it just won't work for this specific data set:

294834289 476607837
560992068 2352984973
560992068 575083378
229711468 204058748
2432968663 2172432571
2473095109 2601551818    
...

R throws me this error:

Error in read.graph.edgelist(file, ...) : 
At structure_generators.c:84 : Invalid (negative) vertex id, Invalid vertex id

The only difference I see between this dataset and the ones I previously used is that those were in sorted form, starting from 1:

1 1
1 2
2 4
...

Any clues?

like image 604
seekme_94 Avatar asked Jan 09 '23 19:01

seekme_94


1 Answers

It seems likely that it's trying to interpret the values as indexes rather than node names and it's probably storing them in a signed integer field that is too small and is probably overflowing into negative numbers. One potential work around is

library("igraph")

dd <- read.table("test.txt")
gg <- graph.data.frame(dd, directed=FALSE)
plot(gg)

enter image description here

It seems this method doesn't have the overflow problem (assuming that's what it was).

like image 134
MrFlick Avatar answered Jan 12 '23 07:01

MrFlick