Learn R Programming

rgraph6 (version 2.0-4)

as_digraph6: Encode network data as 'digraph6' symbols

Description

Generic function encoding directed networks as 'digraph6' symbol(s). See below for available methods.

Usage

as_digraph6(object)

# S3 method for matrix as_digraph6(object)

# S3 method for igraph as_digraph6(object)

# S3 method for network as_digraph6(object)

# S3 method for list as_digraph6(object)

# S3 method for default as_digraph6(object)

Value

A character vector of 'digraph6' symbols.

Arguments

object

a matrix, an igraph object or a network object or a list thereof. See Methods section below.

Methods (by class)

  • as_digraph6(matrix): Expects object to be a square matrix which is interpreted as an adjacency matrix of a directed graph.

  • as_digraph6(igraph): Igraph object needs to be a directed graph. Requires igraph package.

  • as_digraph6(network): Network object needs to be directed network. Requires network package.

  • as_digraph6(list): If object is a list the function is applied to each element. Consequently, it can be a list with a mixture of supported objects classes (adjacency matrices, igraph, or network objects).

  • as_digraph6(default): Throws an error about the unhandled class.

Details

The 'digraph6' format is designed for directed graphs. Error is thrown in case it is given an undirected network.

Examples

Run this code
# From adjacency matrix ----------------------------------------------------
am <- matrix(c(
  0,1,0,
  0,0,1,
  1,0,0),
  byrow=TRUE, ncol=3, nrow=3)
as_digraph6(am)

# From igraph objects ------------------------------------------------------
if(requireNamespace("igraph", quietly=TRUE)) {
  g <- igraph::graph_from_adjacency_matrix(am)
  as_digraph6(g)
}

# From network objects -----------------------------------------------------
if(requireNamespace("network", quietly=TRUE)) {
  net <- network::network(am)
  as_digraph6(net)
}

Run the code above in your browser using DataLab