as.data.frame.cograph_network: Cograph Network as a Data Frame

View source: R/class-network.R

as.data.frame.cograph_networkR Documentation

Cograph Network as a Data Frame

Description

The tidy accessor for a cograph_network: one row per edge (or per node), with endpoints given as labels rather than internal indices, so no caller has to reach into the object with $ or translate integer ids by hand.

Usage

## S3 method for class 'cograph_network'
as.data.frame(
  x,
  row.names = NULL,
  optional = FALSE,
  ...,
  what = c("edges", "nodes")
)

Arguments

x

A cograph_network object.

row.names

NULL or a character vector of row names, as for as.data.frame.

optional

Logical, as for as.data.frame. Ignored; the column names of the returned table are always the documented ones.

...

Unused, for compatibility with the generic.

what

Which table to return. "edges" (default) or "nodes".

Value

A base data frame. For what = "edges", one row per edge with columns from and to (node labels), weight, and any extra edge columns the network carries (for example session). For what = "nodes", one row per node with the node metadata columns (id, label, layout coordinates, and any custom columns).

This is the accessor, so it hands back everything the object holds, including columns mutate_edges computed. to_df is the narrower conversion verb: it returns from, to and weight only.

See Also

to_df, get_edges, get_nodes

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")
net <- as_cograph(adj)

as.data.frame(net)
as.data.frame(net, what = "nodes")

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