Q:

Deleting a single node in R

I'm trying to visualize a preferential network of products using R. I already have a graph of the product network using igraph, but I want to see what would happen if I were to remove one product. I found that I can delete a node using 
g2 <- g - V(g)[15]

but it would also delete all the edges connected to that specific node.
Is there any way to delete just the node and to see how the other nodes reconnect to each other after the deletion of that one node? Any help in this matter is appreciated.
P.S.
Hopefully this will make it clearer:
For example, if we generate the random graph:
set.seed(10)
Data <- data.frame(
  X = sample(1:10),
  Y = sample(3, 10, replace=T)
)
d <- graph.data.frame(Data)
plot(d)
d2 <- d-V(d)[2] #deleting '3' from the network
plot(d2)

If you notice, when you delete the node '3' from the network, node '9' remains unconnected. Is there a way to see the new edge of node '9' after node '3' is connected? Still following the same plot, we would expect that it would connect to node '2'. Is there a function that does this in igraph? Or should i make a code for it?

A:

Maybe not the most efficient way, but it should work :
library(igraph)

set.seed(10) # for plot images reproducibility

# create a graph
df <- data.frame(
  X = c('A','A','B','B','D','E'),
  Y = c('B','C','C','F','B','B')
)
d <- graph.data.frame(df)

# plot the original graph
plot(d)

# function to remove the vertex
removeVertexAndKeepConnections <- function(g,v){

  # we does not support multiple vertices
  stopifnot(length(v) == 1)

  vert2rem <- V(g)[v]

  if(is.directed(g) == FALSE){
    # get the neigbors of the vertex to remove
    vx <- as.integer(V(g)[nei(vert2rem)])
    # create edges to add before vertex removal
    newEdges <- as.matrix(unique(expand.grid(vx,vx)))
    # remove the cycles
    newEdges <- newEdges[newEdges[,1] != newEdges[,2],]
    # sort each row index to remove all the duplicates
    newEdges <- t(apply(newEdges,1,sort))
    newEdges <- unique(newEdges)
  }else{
    # get the ingoing/outgoing neigbors of the vertex to remove
    vx <- as.integer(V(g)[nei(vert2rem,mode='in')])
    vy <- as.integer(V(g)[nei(vert2rem,mode='out')])
    # create edges to add before vertex removal
    newEdges <- as.matrix(unique(expand.grid(vx,vy)))
  }

  # remove already existing edges
  newEdges <- newEdges[!apply(newEdges,MARGIN=1,FUN=function(x)are.connected(g,x[1],x[2])),]

  # add the edges
  g <- g + edges(as.integer(t(newEdges)))
  # remove the vertex
  g <- g - vertex(vert2rem)

  return(g)
}

# let's remove B (you can also use the index
v <- 'B'
plot(removeVertexAndKeepConnections(d,v))

Original :

Modified :

