if (requireNamespace("igraph", quietly = TRUE)) {
g <- igraph::make_graph("Zachary")
# Basic label propagation
comm <- community_label_propagation(g)
# With some nodes fixed to specific communities
initial <- rep(NA, igraph::vcount(g))
initial[1] <- 1 # Node 1 in community 1
initial[34] <- 2 # Node 34 in community 2
fixed <- !is.na(initial)
initial[is.na(initial)] <- seq_len(sum(is.na(initial)))
comm2 <- community_label_propagation(g, initial = initial, fixed = fixed)
}
net <- as_cograph(matrix(runif(25), 5, 5))
com_lp(net)
Run the code above in your browser using DataLab