For example if we have a graph 1-2-3 and delete the vertex 2, then the graph will be 1-3. I have a huge graph with 10000000+ vertices, so I can't delete and create all of them by hand. When I use delete.vertices(g, verticesToDelete)
it automatically deletes the edges that they had with their neighbors.
Let's say we have a graph of the stackoverflow users and badges, where an edge means that a user has that badge. I want to have edges between all the users that have that badge. Below is a code sample :
users <- c(1,2,3,4,5,6,7,8)
badges <- c('Teacher','Teacher','Teacher','Student','Student','Student','Popular Question','Popular Question')
edgeList <- data.frame(users,badges)
library(igraph)
g <- graph_from_data_frame(edgeList,directed = FALSE)
plot(g)
verticesToDelete <- c('Teacher','Student','Popular Question')
g2 <- delete.vertices(g, verticesToDelete)
plot(g2)
# I want the graph to be like the one below after the deletions
users1 <- c(1,1,2,4,4,5,7)
users2 <- c(2,3,3,5,6,6,8)
edgeList2 <- data.frame(users1,users2)
g3 <- graph_from_data_frame(edgeList2,directed = FALSE)
plot(g3)