如何压扁网络对象?

时间:2014-04-02 23:36:45

标签: r network-analysis

我有一个library(network)对象,其中两个节点之间有5条边,我想将它展平为只有1条边。我怎么能做到这一点?

奇怪的是,在网络属性中,它表示不允许多个边缘(FALSE):

 Network attributes:
  vertices = 2 
  directed = TRUE 
  hyper = FALSE 
  loops = TRUE 
  multiple = FALSE 
  bipartite = FALSE 
  total edges= 5 
    missing edges= 0 
    non-missing edges= 5 

 Vertex attribute names: 
    vertex.names 

以下是dput()

> dput(graph_objects$`2115`)
structure(list(mel = list(structure(list(inl = 1L, outl = 2L, 
atl = structure(list(na = FALSE), .Names = "na")), .Names = c("inl", 
"outl", "atl")), structure(list(inl = 2L, outl = 1L, atl = structure(list(
na = FALSE), .Names = "na")), .Names = c("inl", "outl", "atl"
)), structure(list(inl = 2L, outl = 2L, atl = structure(list(
na = FALSE), .Names = "na")), .Names = c("inl", "outl", "atl"
)), structure(list(inl = 2L, outl = 2L, atl = structure(list(
na = FALSE), .Names = "na")), .Names = c("inl", "outl", "atl"
)), structure(list(inl = 1L, outl = 2L, atl = structure(list(
na = FALSE), .Names = "na")), .Names = c("inl", "outl", "atl"
))), gal = structure(list(n = 2, mnext = 6L, directed = TRUE, 
hyper = FALSE, loops = TRUE, multiple = FALSE, bipartite = FALSE), .Names = c("n", 
"mnext", "directed", "hyper", "loops", "multiple", "bipartite"
)), val = list(structure(list(na = FALSE, vertex.names = "dbussink"), .Names = c("na", 
"vertex.names")), structure(list(na = FALSE, vertex.names = "sdaubert"), .Names = c("na", 
"vertex.names"))), iel = list(c(5L, 1L), c(4L, 3L, 2L)), oel = list(
2L, c(4L, 5L, 3L, 1L))), .Names = c("mel", "gal", "val", 
"iel", "oel"), class = "network")

1 个答案:

答案 0 :(得分:0)

使用delete.edges方法按ID删除边缘。

delete.edges(nt2, 2:5)

  #  Network attributes:
  #   vertices = 2
  #   directed = TRUE
  #   hyper = FALSE
  #   loops = TRUE
  #   multiple = FALSE
  #   bipartite = FALSE
  #   total edges= 1
  #     missing edges= 0
  #     non-missing edges= 1
  #
  #  Vertex attribute names:
  #     vertex.names
  #
  # No edge attributes