从 R 图中提取顶点

extract vertex from a R graph

我有以下问题。
一个叫做 tutti
的有向图 我有一个名为 tabellaerrori 的向量,每个位置都包含一个顶点
现在我的问题是:
我想创建一个包含顶点列表的数组,这些顶点列表都在图蒂图和错误向量中。
我使用了以下代码但它不起作用:

risultato<-as.character(相交(tabellaerrori,V(tutti)))

它总是让我返回 tabellaerrori 的内容 怎么了?

对于那些没有经历过不可下载的 google plus 图片库的人,actual 生成错误的行是:

graph.neighborhood(tutti, vcount(tutti), risultato, "out")
## Error in as.igraph.vs(graph, nodes) : Invalid vertex names

help - graph.neighborhood(graph, order, nodes=V(graph), mode=c("all", "out", "in")) 期望 nodes 是一个实际的 igraph 顶点序列。您只需要确保相交的节点处于该形式即可。

以下是 jbaums 的可重现示例的含义(前提是我从您的屏幕截图中做出了正确的假设):

library(igraph)

set.seed(1492) # makes this more reproducible

# simulate your overall graph

tutti <- graph.full(604, directed=TRUE)
V(tutti)$name <- as.character(sample(5000, 604))

# simulate your nodes

tabellaerrori <- as.character(c(sample(V(tutti), 79), sample(6000:6500, 70)))
names(tabellaerrori) <- as.numeric(tabellaerrori)

# give a brief view of the overall data objects

head(V(tutti))
## Vertex sequence:
## [1] "1389" "1081" "922"  "553"  "261"  "42"

length(V(tutti))
## [1] 604

head(tabellaerrori)
##   293   415   132   299   408   526 
## "293" "415" "132" "299" "408" "526"

length(tabellaerrori)
## [1] 149

# for your answer, find the intersection of the vertext *names*

risultato <- as.character(intersect(tabellaerrori, V(tutti)$name))
risultato
## Vertex sequence:
## [1] "293" "132" "155" "261" "68"  "381" "217" "394" "581"

# who are the ppl in your neighborhood

graph.neighborhood(tutti, vcount(tutti), risultato, "out")
## [[1]]
## IGRAPH DN-- 604 364212 -- Full graph
## + attr: name (g/c), loops (g/l), name (v/c)
## 
## [[2]]
## IGRAPH DN-- 604 364212 -- Full graph
## + attr: name (g/c), loops (g/l), name (v/c)
##
## ... (a few more)

您之前真正所做的(即intersect在幕后所做的)是:

risultato <- as.character(intersect(tabellaerrori, as.character(V(tutti))))

因此,您的 Invalid vertex names 错误。