【发布时间】:2016-07-30 09:29:36
【问题描述】:
我正在尝试为节点列表创建网络邻居数据集。我虽然可以使用邻居命令的 lapply 函数来做到这一点。作为一个额外的复杂因素,我的一些查找节点不在图表中,但无论如何我都无法让它工作。
这是一个例子:
edgelist <- read.table(text = "
A B
B C
C D
D E
C F
F G")
testlist <- read.table(text = "
A
H
C
D
J")
testlist2 <- read.table(text = "
A
C
B
D
E")
library(igraph)
graph <- graph.data.frame(edgelist)
str(graph)
neighbors<- lapply(testlist2, function(p) { #Each pledge_id
temp=neighbors(graph,p) #Find all the neighbors for that pledge
return(temp)
})
neighbors<- lapply(testlist, function(p) { #Each pledge_id
temp=neighbors(graph,p) #Find all the neighbors for that pledge
return(temp)
})
不幸的是,这在这两种情况下都会返回废话。我错过了什么?
我想要的输出是这样的:
lookupnode neighbor
A B
H .
C D
C F
D E
J .
我知道最终我需要在某个地方添加一个 temp=data.table::rbindlist(temp) 命令,但我认为这不会导致大肆宣传。
【问题讨论】: