View source: R/wrangle-structure.R
| contract_nodes | R Documentation |
Replaces each group of nodes with a single node whose edges aggregate the
edges of its members. The counterpart of igraph::contract() and
tidygraph's to_contracted(), and the network form of what
summarize_clusters() computes inside an analysis object.
contract_nodes(
x,
groups,
weight = c("sum", "mean", "max", "min"),
loops = FALSE,
keep_format = FALSE,
directed = NULL
)
x |
Network input. |
groups |
Group assignment. Either a vector with one entry per node (in node order), or a named list mapping group name to node labels. |
weight |
How to aggregate the weights of the edges that fall between
two groups: |
loops |
Logical. Keep the within-group edges as self-loops on the contracted node. Default FALSE. |
keep_format |
Logical. Return the input format when TRUE. |
directed |
Logical or NULL. If NULL (default), auto-detect. |
A cograph_network with one node per group, labeled by group
name, or the input format when keep_format = TRUE.
summarize_clusters, detect_communities,
split_components
adj <- matrix(c(0, 1, 1, 0,
1, 0, 0, 1,
1, 0, 0, 1,
0, 1, 1, 0), 4, 4, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B", "C", "D")
contract_nodes(adj, groups = c("left", "left", "right", "right"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.