0

After several operations on an igraph object (g), I have ended up with the "id" attribute becoming full of nested lists.

It looks like this:

head(V(g)$id)

[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[1] "http://www.parliament.uk/"


[[2]]
[[2]][[1]]
[[2]][[1]][[1]]
[1] "http://www.businesslink.gov.uk/"


[[3]]
[[3]][[1]]
[[3]][[1]][[1]]
[1] "http://www.number10.gov.uk/"

... and so forth.

I need to 'unnest' this list so it becomes:

head(V(g)$id)
[1] "http://www.parliament.uk/"       "http://www.businesslink.gov.uk/"
[3] "http://www.number10.gov.uk/"     "http://www.ombudsman.org.uk/"
[5] "http://www.hm-treasury.gov.uk/"  "http://data.gov.uk/"

The nested list is causing problems when igraph exports the object to a graphml file. It results in the "id" being assigned default labels (e.g. n0, n1, n2...).

I have tried several other questions, particularly this one. However, I cannot get it to work. It is really frustrating!

Community
  • 1
  • 1
timothyjgraham
  • 1,142
  • 1
  • 15
  • 28

1 Answers1

2

Are you just looking for unlist, perhaps?

L <- list(list(list("A")), list(list("B")))
L
# [[1]]
# [[1]][[1]]
# [[1]][[1]][[1]]
# [1] "A"
# 
#
#
# [[2]]
# [[2]][[1]]
# [[2]][[1]][[1]]
# [1] "B"
#
#
#
unlist(L)
# [1] "A" "B"
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485