简体   繁体   中英

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?

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)

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM