Learn R Programming

cograph (version 2.0.0)

select_component: Select Connected Component

Description

Select nodes belonging to a specific connected component.

Usage

select_component(
  x,
  which = "largest",
  ...,
  .keep_edges = c("internal", "none"),
  keep_format = FALSE,
  directed = NULL
)

Value

A cograph_network with nodes in the selected component.

Arguments

x

Network input.

which

Component selection:

"largest"

(default) The largest connected component

Integer

Component by ID

Character

Component containing the named node

...

Additional filter expressions to apply after component selection.

.keep_edges

How to handle edges. Default "internal".

keep_format

Logical. Keep input format? Default FALSE.

directed

Logical or NULL. Auto-detect if NULL.

See Also

select_nodes, select_neighbors

Examples

Run this code
# Create disconnected network
adj <- matrix(0, 6, 6)
adj[1, 2] <- adj[2, 1] <- 1
adj[1, 3] <- adj[3, 1] <- 1
adj[4, 5] <- adj[5, 4] <- 1
adj[5, 6] <- adj[6, 5] <- 1
adj[4, 6] <- adj[6, 4] <- 1
rownames(adj) <- colnames(adj) <- LETTERS[1:6]

# Largest component
select_component(adj, which = "largest")

# Component containing node "A"
select_component(adj, which = "A")

Run the code above in your browser using DataLab