Learn R Programming

cograph (version 2.0.0)

to_igraph: Convert Network to igraph Object

Description

Converts various network representations to an igraph object. Supports matrices, igraph objects, network objects, cograph_network, and tna objects.

Usage

to_igraph(x, directed = NULL)

Value

An igraph object.

Arguments

x

Network input. Can be:

  • A square numeric matrix (adjacency/weight matrix)

  • An igraph object (returned as-is or converted if directed differs)

  • A statnet network object

  • A cograph_network object

  • A tna object

directed

Logical or NULL. If NULL (default), auto-detect from matrix symmetry. Set TRUE to force directed, FALSE to force undirected.

See Also

to_data_frame, as_cograph

Examples

Run this code
# From matrix
adj <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), 3, 3)
rownames(adj) <- colnames(adj) <- c("A", "B", "C")
g <- to_igraph(adj)

# Force directed
g_dir <- to_igraph(adj, directed = TRUE)

Run the code above in your browser using DataLab