0

I have the following problem.
A directed graph called tutti
I have a vector called tabellaerrori containing a vertex in each position
Now my problem is:
I want to create an array cointaining the list of vertex which are both in tutti graph and in errori vector.
I used the following code but it doesn't work:

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

It gives me back always the content of tabellaerrori What's wrong ?

Alex Fort
  • 93
  • 6
  • Please provide reproducible example – akrun Jan 19 '15 at 11:19
  • https://plus.google.com/u/0/115505398072903675944/posts/4jxcckeLQpT?pid=6106016935769662722&oid=115505398072903675944 https://plus.google.com/u/0/115505398072903675944/posts/4jxcckeLQpT?pid=6106016949694762914&oid=115505398072903675944 https://plus.google.com/u/0/115505398072903675944/posts/4jxcckeLQpT?pid=6106016965557307874&oid=115505398072903675944 – Alex Fort Jan 19 '15 at 11:47
  • The first pic is the vertex list V(tutti) – Alex Fort Jan 19 '15 at 11:48
  • The second pic is the list of the vertex i want to start from – Alex Fort Jan 19 '15 at 11:48
  • The third pic is the strange error .... can't find why ... – Alex Fort Jan 19 '15 at 11:49
  • You should read [this](http://stackoverflow.com/q/5963269/489704) and [this](http://stackoverflow.com/help/mcve). – jbaums Jan 19 '15 at 11:50

1 Answers1

1

For those who didn't suffer through the non-downloadable google plus image gallery, the actual line generating the error is:

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

From the help - graph.neighborhood(graph, order, nodes=V(graph), mode=c("all", "out", "in")) is expecting nodes to be an actual igraph vertex sequence. You just need to make sure your intersected nodes are in that form.

Here's what jbaums meant by a reproducible example (provided I've made the right assumptions from your screen captures):

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)

What you were really doing before (i.e. what intersect was doing under the covers) is:

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

hence, your Invalid vertex names error.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205