to_data_frame: Export Network as Edge List Data Frame

View source: R/network-utils.R

to_data_frameR Documentation

Export Network as Edge List Data Frame

Description

Converts a network to an edge list data frame with columns for source, target, and weight.

Usage

to_data_frame(x, directed = NULL)

to_df(x, directed = NULL)

Arguments

x

Network input: matrix, igraph, network, cograph_network, or tna object.

directed

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

Value

A data frame with columns:

  • from: Source node name/label

  • to: Target node name/label

  • weight: Edge weight

See Also

to_df, to_igraph, as_cograph

Examples

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")

# Convert to edge list
to_data_frame(adj)

# Use alias
to_df(adj)

cograph documentation built on April 1, 2026, 1:07 a.m.