Learn R Programming

cograph (version 2.7.2)

add_nodes: Add Nodes to a Network

Description

Add Nodes to a Network

Usage

add_nodes(x, labels, ..., keep_format = FALSE, directed = NULL)

Value

A cograph_network with the new nodes appended (isolated until edges are added), or the input format when keep_format = TRUE.

Arguments

x

Network input.

labels

Character vector of labels for the new nodes.

...

Named vectors of node attributes for the new nodes, each of length 1 (recycled) or length(labels). Columns the network does not already have are created and filled with NA for the existing nodes.

keep_format

Logical. Return the input format when TRUE.

directed

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

See Also

remove_nodes, add_edges, mutate_nodes

Examples

Run this code
adj <- matrix(c(0, 1, 1, 0), 2, 2)
rownames(adj) <- colnames(adj) <- c("A", "B")

add_nodes(adj, labels = c("C", "D"))
add_nodes(adj, labels = "C", group = "new")

Run the code above in your browser using DataLab