I have a network/graph (test_FINAL), from which I want to remove a certain set of vertices below:
vertex <- c(1, 3, 7, 9, 10)
The idea is to run a clustering analyses after the vertices are removed. For example, in the first iteration, vertex #1 should be removed and then, vertices #1 and #3, and the subsequent #1, #3, #7 and so on until the final iteration where all the vertices are removed and clustering performed.
My code looks as follows:
# Library
library(igraph)
# Create data
set.seed(1)
data <- matrix(sample(0:1, 100, replace=TRUE, prob=c(0.8,0.2)), nc=10)
network <- graph_from_adjacency_matrix(data , mode='undirected', diag=F )
# Default network
par(mar=c(0,0,0,0))
plot(network)
vertex <- c(1, 3, 7, 9, 10)
# Estimating cluster statistics *prior to* removing vertices
pre_cluster <- cluster_fast_greedy(network)
length(pre_cluster); sizes(pre_cluster); modularity(pre_cluster)
# removing vertices
final_graph <- delete_vertices(network, c(vertex))
cluster_graph <- cluster_fast_greedy(final_graph)
# Estimating cluster statistics *after* removing vertices
length(cluster_graph); sizes(cluster_graph); modularity(cluster_graph)
What is the best way to do this in a loop, especially for the final iteration where all the vertices are removed and then the cluster statistics are estimated?