'R igraph Cannot add edges, Invalid Vertex ID
When trying to add edges to my graph using this line. I get "cannot add edges, Invalid vertex id"
graph <- add_edges(graph,c(as.character(Edgelist$A1[i]),as.character(Edgelist$A2[i])))
I have added my vertices to this graph with this code as follows
graph <- make_empty_graph(directed=FALSE)
for (i in 1:(length(unique(monthdata$AuthorID)))){
graph <- add_vertices(graph,1,authorID=as.character(monthdata$AuthorID[i]))
}
I then attempt to add edges to this graph using the following nested loop
for(k in unique(monthdata$ThreadID)){
temp = monthdata[(monthdata$ThreadID==k),]
Edgelist = as.data.frame(t(combn(temp$AuthorID,2)))
colnames(Edgelist) = c("A1","A2")
for(i in 1:nrow(Edgelist)){
graph <- add_edges(graph,c(as.character(Edgelist$A1[i]),as.character(Edgelist$A2[i])))
}
}
Any help would be greatly appreciated I cannot seem to figure out what is giving me this "cannot add edges, invalid vertex id" error.
I would like to add this is NOT solvable by similarly titled posts. I have read and attempted their solutions but it doesn't seem to work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
