Learn R Programming

cograph (version 2.0.0)

select_neighbors: Select Node Neighbors (Ego Network)

Description

Select nodes within a specified distance from focal nodes.

Usage

select_neighbors(
  x,
  of,
  order = 1L,
  ...,
  .keep_edges = c("internal", "none"),
  keep_format = FALSE,
  directed = NULL
)

Value

A cograph_network with nodes in the neighborhood.

Arguments

x

Network input.

of

Character or integer. Focal node(s) by name or index.

order

Integer. Neighborhood order (1 = direct neighbors). Default 1.

...

Additional filter expressions to apply after neighborhood 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_component

Examples

Run this code
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")

# Direct neighbors of A
select_neighbors(adj, of = "A")

# Neighbors up to 2 hops
select_neighbors(adj, of = "A", order = 2)

Run the code above in your browser using DataLab