0

The graph is

a b 1
a b 2
b a 3
a a 4
a a 2

g = read.graph('this_file.ncol', format = 'ncol', directed = TRUE)

when I use the as.undirected(g,mode="collapse"), I get

a a 7
a b 5

Why? What I expect is

a a 6
a b 6

Is this a bug, or I do not understand the meaning of 'collapse'?

Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
Ben
  • 665
  • 1
  • 10
  • 27

1 Answers1

1

I can reproduce this. This is what I get:

cat(file = tmp <- tempfile(), 
"a b 1
a b 2
b a 3
a a 4
a a 2
")

g <- read.graph(tmp, format = 'ncol', directed = TRUE)

g2 <- as.undirected(g, mode = "collapse")
get.data.frame(g2)
#   from to weight
# 1    a  a      7
# 2    a  b      5

igraph.version()
# [1] "0.7.1"

So it seems that it is indeed a bug. Please report it at https://github.com/igraph/igraph. Thanks.

It seems that as.undirected() has problems with multiple edges. This is a workaround:

# g3 <- as.undirected(simplify(g, remove.loops = FALSE))
# get.data.frame(g3)
#   from to weight
# 1    a  a      6
# 2    a  b      6
Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
  • Thanks. As you said, first simplify the graph, then use the as.undirected function. It would be OK. – Ben Aug 01 '14 at 03:01