View source: R/network-utils.R
| select_nodes | R Documentation |
A more nuanced node selection function that improves upon filter_nodes()
with lazy centrality computation (only computes measures actually referenced),
multiple selection modes, and global context variables for structural awareness.
select_nodes(
x,
...,
name = NULL,
index = NULL,
top = NULL,
by = "degree",
neighbors_of = NULL,
order = 1L,
component = NULL,
.keep_edges = c("internal", "none"),
keep_format = FALSE,
directed = NULL
)
x |
Network input: cograph_network, matrix, igraph, network, or tna object. |
... |
Filter expressions using node columns, centrality measures, or global context variables. Centrality measures are computed lazily (only those actually referenced). Available variables:
|
name |
Character vector. Select nodes by name/label. |
index |
Integer vector. Select nodes by index (1-based). |
top |
Integer. Select top N nodes by centrality measure. |
by |
Character. Centrality measure for top selection. Default |
neighbors_of |
Character or integer. Select neighbors of these nodes (by name or index). |
order |
Integer. Neighborhood order (1 = direct neighbors, 2 = neighbors of neighbors, etc.). Default 1. |
component |
Selection mode for connected components:
|
.keep_edges |
How to handle edges. One of:
|
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 (like tidygraph/dplyr):
select_nodes(x, top = 10, component = "largest") selects
top 10 nodes within the largest component
All criteria must be satisfied for a node to be selected
Centrality measures are computed lazily - only measures actually referenced
in expressions or the by parameter are computed. This makes
select_nodes() faster than filter_nodes() for large networks.
For networks with negative edge weights, betweenness and closeness
will return NA with a warning (igraph cannot compute these with negative weights).
A cograph_network object with selected nodes. If keep_format = TRUE,
returns the same type as input.
filter_nodes, select_neighbors,
select_component, select_top
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")
# Lazy - only computes degree
select_nodes(adj, degree >= 3)
# Global context - computes component info
select_nodes(adj, is_largest_component & degree >= 2)
# By name
select_nodes(adj, name = c("A", "B", "C"))
# Top 2 by PageRank
select_nodes(adj, top = 2, by = "pagerank")
# Neighborhood of "A" up to 2 hops
select_nodes(adj, neighbors_of = "A", order = 2)
# Largest connected component
select_nodes(adj, component = "largest")
# Combined: top 2 in largest component
select_nodes(adj, component = "largest", top = 2, by = "degree")
# Articulation points with high degree
# select_nodes(adj, is_articulation & degree >= 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.