0

我正在尝试通过我的出版网络建立我的合作网络。我使用了非常适合它的 igraph。然而,由于我的顶点(在网络中代表我的那个)到所有共同作者都有边,我最终得到了一个非常紧凑的图。我想从我的顶点删除一些仅与另一位作者相关的作者的边。基本上是我只是合着的作者。无论如何,我已经确定了这些顶点并且我知道我的顶点。现在我找不到一种方法来删除仅将这组边缘链接到我的边缘。

更一般地,您如何从两组向量中删除边缘,例如 V(g)[a] 和 V(g)[b]?

谢谢,

这是一个例子:

au1 <- c('deb', 'art', 'deb', 'seb', 'deb', 'deb', 'mar', 'mar', 'joy', 'deb')
au2 <- c('art', 'deb', 'soy', 'deb', 'joy', 'ani', 'deb', 'deb', 'nem', 'mar')
au3 <- c('mar', 'lio', 'mil', 'mar', 'ani', 'lul', 'nem', 'art', 'deb', 'tat')


tata <- data.frame(au1, au2, au3)
xaulist2 <- levels(factor(unlist(tata[,])))
xaulist <- levels(as.factor(xaulist2))
xaulist_att <- c(rep('prime', 2), 'main', 'second', 'second', rep('prime', 3), 'second', rep('prime', 3))
au_att <- data.frame(au_name=xaulist, level=xaulist_att)

# matrix list preparation
tutu <- matrix(NA, nrow=length(xaulist), ncol=dim(tata)[1]) # row are authors and col are papers
for (i in 1:length(xaulist))
{
  for (j in 1:dim(tata)[1])
  {
  ifelse('TRUE' %in% as.character(tata[j,]==xaulist[i]), tutu[i,j] <- 1,  tutu[i,j] <- 0)
  }
}
tutu[is.na(tutu)] <- 0

tutu[tutu>=1] <- 1 # change it to a Boolean matrix
termMatrix <- tutu %*% t(tutu)

# build a graph from the above matrix
g <- graph.adjacency(termMatrix, weighted=T, mode = 'undirected')
g <- simplify(g) # remove loops
V(g)$label <- xaulist # set labels of vertices
V(g)$degree <- degree(g) # set degrees of vertices
V(g)[xaulist_att=='second']$color <- 'red'
V(g)[xaulist_att=='main']$color <- 'blue'
set.seed(112) # set seed to make the layout reproducible
plot(g)

所以问题是如何从具有“第二”属性的作者到具有“主要”属性的作者中删除边缘,即从红色到蓝色?

再次感谢,

4

2 回答 2

5

这是一种方法,它认为它非常可读:

g2 <- delete.edges(g, E(g)[ V(g)[xaulist_att == 'second'] %--% 
                            V(g)[xaulist_att == 'main'  ] ])

## plot the results
coords <- layout.auto(g)
layout(rbind(1:2))
plot(g, layout=coords, main="g")
plot(g2, layout=coords, main="g2")

详情请参阅?iterators

于 2013-01-13T15:37:24.300 回答
1

如果没有可重复的示例,我不确定我是否了解您想要的内容。但这应该可以帮助您:

##deletes from g edge 1->2.
g <- delete.edges(g, E(g, P=c(1,2))) 
于 2013-01-13T09:17:46.140 回答