Learn R Programming

cograph (version 2.7.2)

to_undirected: Convert a Directed Network to Undirected

Description

Collapses each pair of opposite arcs into one undirected edge. The counterpart of igraph::as_undirected() and tidygraph's to_undirected().

Usage

to_undirected(
  x,
  method = c("max", "sum", "mean", "min", "mutual"),
  keep_format = FALSE,
  directed = NULL
)

Value

An undirected cograph_network, or the input format when keep_format = TRUE. Zero is how this representation stores "no edge", so any pair whose combined weight is exactly zero disappears: every unreciprocated arc under method = "mutual", and a cancelling pair under "sum". A cograph_edges_dropped warning says how many.

Arguments

x

Network input.

method

How to combine w[i, j] and w[j, i]: "max" (default), "sum", "mean", "min", or "mutual" (keep only reciprocated pairs, taking the minimum weight).

keep_format

Logical. Return the input format when TRUE.

directed

Logical or NULL. Directedness to read the input with.

See Also

to_directed, symmetrize

Examples

Run this code
adj <- matrix(c(0, .5, 0,
                .2, 0, .7,
                0, 0, 0), 3, 3, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B", "C")

to_undirected(adj, method = "sum")
to_undirected(adj, method = "mutual")

Run the code above in your browser using DataLab