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 = TRUE,
keep_format = FALSE,
directed = NULL,
.keep_isolates = NULL
)A cograph_network object with selected edges. If keep_format = TRUE,
matrix, igraph, and statnet network inputs are converted back to that type.
Nodes left without edges are kept and reported in a
cograph_isolates_created warning, unless
keep_isolates = FALSE.
Network input: cograph_network, matrix, igraph, network, or tna object.
Filter expressions using edge columns or computed metrics. Available variables:
from, to, weight, plus any custom
abs_weight, from_degree, to_degree,
from_strength, to_strength, edge_betweenness,
weight_rank
is_bridge, is_mutual (alias
is_reciprocal), is_loop, is_multiple,
same_community
from_label, to_label,
from_community, to_community
Integer. Select top N edges by a metric.
Character. Metric for top selection. Default "weight".
Options: "weight", "abs_weight", "edge_betweenness",
"from_degree", "to_degree", "from_strength",
"to_strength", "weight_rank".
Character or integer. Select edges involving these nodes (by name or index). An edge is selected if either endpoint matches.
List of two character/integer vectors. Select edges between
two node sets. Example: between = list(c("A", "B"), c("C", "D")).
Logical. Select only bridge edges (edges whose removal disconnects the graph). Default FALSE.
Logical. For directed networks, select only mutual (reciprocated) edges. Default FALSE.
Character. Community detection method for same_community
variable. One of "louvain", "walktrap", "fast_greedy",
"label_prop", "infomap", "leiden". Default "louvain".
Logical. Keep nodes that end up with no edges?
Default TRUE, matching igraph::delete_edges() and tidygraph:
filtering edges does not remove nodes. Set FALSE to drop them, or call
remove_isolates() afterwards.
Logical. If TRUE, matrix, igraph, and statnet network inputs are returned in that format. Default FALSE returns cograph_network.
Logical or NULL. If NULL (default), auto-detect.
Deprecated. Use keep_isolates.
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.
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")
select_edges(adj, weight > 0.5)
select_edges(adj, top = 3)
select_edges(adj, involving = "A")
select_edges(adj, between = list(c("A", "B"), c("C", "D")))
Run the code above in your browser using DataLab