0

I saw that igraph in R requires data structured like this:

nodeA  nodeB   int_1 int_2
AA      BD      6   X   
BD      CA      8   Y
AA      DE      7   Y
...     ...     ... ...

And I saw that through

data<-read.table(file)
graph.data.frame(data)

I obtain the corresponding network.

Now say I have to put in isolated nodes, I searched in the documentation but could not find anything that answered my issue.

How can I specify them in the original file?

I thought of something like (like a .sif format)

nodeA  nodeB   int_1 int_2
AA      DE      7   Y
...     ...     ... ...
isoNodeA
isoNodeB
...

but obviously the read.table does not accept different number of fields between rows.

Marco Pietrosanto
  • 420
  • 1
  • 7
  • 18

1 Answers1

0

You could try it like this:

data<-read.table(header=T, fill = TRUE, stringsAsFactors=F, text="
nodeA  nodeB   int_1 int_2
AA      BD      6   X   
BD      CA      8   Y
AA      DE      7   Y
ZZ
DE      BD      7   Y")
data[data==""] <- NA

library(igraph)
g <- graph.data.frame(
  data[complete.cases(data),], 
  vertices = unique(na.omit(unlist(data[1:2]))))
plot(g)
lukeA
  • 53,097
  • 5
  • 97
  • 100