add_edges: Add Edges to a Network

View source: R/wrangle-edit.R

add_edgesR Documentation

Add Edges to a Network

Description

Add Edges to a Network

Usage

add_edges(x, from, to, weight = 1, ..., keep_format = FALSE, directed = NULL)

Arguments

x

Network input.

from

Source nodes, by label or index.

to

Target nodes, by label or index. The same length as from.

weight

Numeric weight for the new edges, length 1 or length(from). Default 1.

...

Named vectors of extra edge attributes, length 1 or length(from).

keep_format

Logical. Return the input format when TRUE.

directed

Logical or NULL. If NULL (default), auto-detect.

Value

A cograph_network with the new edges, or the input format when keep_format = TRUE. An edge that already exists has its weight replaced, and a cograph_edges_replaced warning says how many.

Note

When the igraph package is attached it masks this function with igraph::add_edges(), which takes an igraph object. Use cograph::add_edges() to be explicit.

See Also

remove_edges, add_nodes, bind_networks

Examples

adj <- matrix(0, 3, 3, dimnames = list(LETTERS[1:3], LETTERS[1:3]))
adj["A", "B"] <- adj["B", "A"] <- 1

add_edges(adj, from = "B", to = "C", weight = 0.5)

cograph documentation built on Sept. 30, 2026, 5:08 p.m.