本文介绍了笔画:从2组向量中移除边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过我的发布网络将我的合作网络联系起来.我用igraph很好.但是,由于我从顶点(网络中代表我的顶点)到所有合著者都有边,因此最终得到了一张漂亮的图表.我想删除顶点中仅与另一作者相关的某些作者的边缘.基本上是我只参与共同创作的作者.无论如何,我已经确定了这些顶点,并且知道了我的顶点.现在,我找不到删除仅将这组边缘链接到我的边缘的方法.

I am trying to network my collaborations through my publication network. I used igraph which is great for it. However, since I have edges from my vertex (the one representing me in the network) to all co-authors I end up with a pretty packed graph. I would like to remove edges from my vertex to some authors that are only related through another author. Basically authors where I was only co-authoring. Anyway, I have identified these vertices and I know my vertex. Now I can't find a way to remove edges that link this set of edges to me only.

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

More generally how do you remove edges from 2 groups of vectors, such as V(g)[a] and 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)

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

So the question is how do you remove edges from authors that have attribute 'second' to the one that has attribute 'main', that is from the red ones to the blue one?

再次感谢

推荐答案

这是一种实现方法,它认为它很可读:

Here is one way to do it, it think it is very readable:

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.

See ?iterators for the details.

这篇关于笔画:从2组向量中移除边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:36