Question

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'?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top