简体   繁体   中英

Error in using asIgraph() function in R to convert a network object to an igraph object?

I am currently trying to convert a network object to an igraph object. From various posts, I understand the intergraph package can do this through the asIgraph() function. I am trying to convert the classic Sampson dataset, which is found in the ergm package. When I do:

> library(ergm)
> library(intergraph)
> library(igraph)
> data(sampson)
> class(samplike) # The network object
[1] "network"
> asIgraph(samplike)
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 88, 26

I have the error above. Does anyone have any idea why it fails for this canonical dataset?

EDIT : See a recent post from two weeks ago on the ergm GitHub Fixed the "nominations" attribute of the sampson dataset. This was an error in the sampson dataset that has now been fixed on the GitHub version, but not yet updated to CRAN.

It's failing because the sampson dataset has an edge attribute nominations which only has 26 values even though there are 88 edges in the dataset. When intergraph tries to convert to igraph it attempts to bind the edge attributes to the edge list with asDF() and this step fails. The simple thing is to delete the edge attribute like so:

smplk<-samplike

delete.edge.attribute(smplk, "nominations")

asIgraph(smplk)

IGRAPH dca72f1 D--- 18 88 -- 
+ attr: cloisterville (v/l), group (v/c), na (v/l), vertex.names
| (v/c), na (e/l)
...

It's a little unclear to me from the documentation how this attribute should map on to the edgelist, but if this can be determined it could be added in separately with set.edge.attribute .

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