View source: R/network-utils.R
| select_edges | R Documentation |
A powerful edge selection function with lazy computation (only computes metrics actually referenced), multiple selection modes, and structural awareness (bridges, communities, reciprocity).
select_edges(
x,
...,
top = NULL,
by = "weight",
involving = NULL,
between = NULL,
bridges_only = FALSE,
mutual_only = FALSE,
community = "louvain",
.keep_isolates = FALSE,
keep_format = FALSE,
directed = NULL
)
x |
Network input: cograph_network, matrix, igraph, network, or tna object. |
... |
Filter expressions using edge columns or computed metrics. Available variables:
|
top |
Integer. Select top N edges by a metric. |
by |
Character. Metric for top selection. Default |
involving |
Character or integer. Select edges involving these nodes (by name or index). An edge is selected if either endpoint matches. |
between |
List of two character/integer vectors. Select edges between
two node sets. Example: |
bridges_only |
Logical. Select only bridge edges (edges whose removal disconnects the graph). Default FALSE. |
mutual_only |
Logical. For directed networks, select only mutual (reciprocated) edges. Default FALSE. |
community |
Character. Community detection method for |
.keep_isolates |
Logical. Keep nodes with no remaining edges? Default FALSE. |
keep_format |
Logical. If TRUE, return the same format as input. Default FALSE returns cograph_network. |
directed |
Logical or NULL. If NULL (default), auto-detect. |
Selection modes are combined with AND logic:
select_edges(x, top = 10, involving = "A") selects
top 10 edges among those involving node A
All criteria must be satisfied for an edge to be selected
Edge metrics are computed lazily - only those actually referenced in expressions or required by selection modes are computed.
A cograph_network object with selected edges. If keep_format = TRUE,
returns the same type as input.
filter_edges, select_nodes,
select_bridges, select_top_edges
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")
# Expression-based (lazy - only computes what's needed)
select_edges(adj, weight > 0.5)
select_edges(adj, abs_weight > 0.4)
# Top N edges by weight
select_edges(adj, top = 3)
select_edges(adj, top = 3, by = "edge_betweenness")
# Edges involving specific nodes
select_edges(adj, involving = "A")
select_edges(adj, involving = c("A", "B"))
# Edges between two node sets
select_edges(adj, between = list(c("A", "B"), c("C", "D")))
# Bridge edges only
select_edges(adj, bridges_only = TRUE)
# Combined: top 3 edges involving A
select_edges(adj, involving = "A", top = 3)
# Using endpoint degrees
select_edges(adj, from_degree >= 3 | to_degree >= 3)
# Within-community edges
select_edges(adj, same_community)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.