if (requireNamespace("igraph", quietly = TRUE)) {
  library(igraph)
  # Generate a weighted and undirected graph
  gsim <- sample_gnp(50, 0.5, directed = FALSE, loops = FALSE)
  PESI <- runif(length(E(gsim)), 0, 1)
  E(gsim)$weight <- PESI
  A <- as_adjacency_matrix(gsim, sparse = FALSE, attr = "weight")
  OnnelaClust <- ClustF(A, "undirected")
  # Generate a weighted and directed graph
  gsim <- sample_gnp(50, 0.5, directed = TRUE, loops = FALSE)
  PESI <- runif(length(E(gsim)), 0, 1)
  E(gsim)$weight <- PESI
  A <- as_adjacency_matrix(gsim, sparse = FALSE, attr = "weight")
  FagioloClust <- ClustF(A, "directed")
} else {
  cat("Please install the 'igraph' package to run this example.\n")
}
Run the code above in your browser using DataLab