View source: R/network-utils.R
| detect_communities | R Documentation |
Detects communities (clusters) in a network using various community detection algorithms. Returns a data frame with node-community assignments.
detect_communities(x, method = "louvain", directed = NULL, weights = TRUE)
x |
Network input: matrix, igraph, network, cograph_network, or tna object. |
method |
Community detection algorithm to use. One of:
|
directed |
Logical or NULL. If NULL (default), auto-detect from matrix symmetry. Set TRUE to force directed, FALSE to force undirected. |
weights |
Logical. Use edge weights for community detection. Default TRUE. |
A data frame with columns:
node: Node labels/names
community: Integer community membership
# Basic usage
adj <- matrix(c(0, .5, .8, 0,
.5, 0, .3, .6,
.8, .3, 0, .4,
0, .6, .4, 0), 4, 4, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B", "C", "D")
detect_communities(adj)
# Different algorithm
detect_communities(adj, method = "walktrap")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.