select_top_edges: Select Top N Edges

View source: R/network-utils.R

select_top_edgesR Documentation

Select Top N Edges

Description

Select the top N edges ranked by weight or another metric.

Usage

select_top_edges(
  x,
  n,
  by = "weight",
  ...,
  .keep_isolates = FALSE,
  keep_format = FALSE,
  directed = NULL
)

Arguments

x

Network input.

n

Integer. Number of top edges to select.

by

Character. Metric for ranking. One of: "weight", "abs_weight", "edge_betweenness". Default "weight".

...

Additional filter expressions.

.keep_isolates

Keep nodes with no edges? Default FALSE.

keep_format

Keep input format? Default FALSE.

directed

Auto-detect if NULL.

Value

A cograph_network with the top N edges.

See Also

select_edges, select_top

Examples

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")

# Top 3 edges by weight
select_top_edges(adj, n = 3)

# Top 2 by edge betweenness
select_top_edges(adj, n = 2, by = "edge_betweenness")

cograph documentation built on April 1, 2026, 1:07 a.m.