Learn R Programming

migraph (version 0.12.1)

as: Coercion between migraph-compatible object classes

Description

The as_ functions in {migraph} coerce objects between several common classes of social network objects. These include:

  • edgelists, as data frames or tibbles

  • adjacency (one-mode/unipartite) and incidence (two-mode/bipartite) matrices

  • {igraph} graph objects

  • {tidygraph} tbl_graph objects

  • {network} network objects

An effort is made for all of these coercion routines to be as lossless as possible, though some object classes are better at retaining certain kinds of information than others. Note also that there are some reserved column names in one or more object classes, which could otherwise lead to some unexpected results.

Usage

as_edgelist(object, twomode = FALSE)

as_matrix(object, twomode = NULL)

as_igraph(object, twomode = FALSE)

as_tidygraph(object, twomode = FALSE)

as_network(object, twomode = FALSE)

as_graphAM(object, twomode = NULL)

Value

The currently implemented coercions or translations are:

to/fromedgelistsmatricesigraphtidygraphnetworksienagoldfish
edgelists (data frames)XXXXXXX
matricesXXXXXXX
igraphXXXXXXX
tidygraphXXXXXXX
networkXXXXXXX
graphAMXXXXXXX

Arguments

object

An object of a migraph-consistent class:

  • matrix (adjacency or incidence) from {base} R

  • edgelist, a data frame from {base} R or tibble from {tibble}

  • igraph, from the {igraph} package

  • network, from the {network} package

  • tbl_graph, from the {tidygraph} package

twomode

Logical option used to override heuristics for distinguishing incidence (two-mode/bipartite) from adjacency (one-mode/unipartite) networks. By default FALSE.

Details

Edgelists are expected to be held in data.frame or tibble class objects. The first two columns of such an object are expected to be the senders and receivers of a tie, respectively, and are typically named "from" and "to" (even in the case of an undirected network). These columns can contain integers to identify nodes or character strings/factors if the network is labelled. If the sets of senders and receivers overlap, a one-mode network is inferred. If the sets contain no overlap, a two-mode network is inferred. If a third, numeric column is present, a weighted network will be created.

Matrices can be either adjacency (one-mode) or incidence (two-mode) matrices. Incidence matrices are typically inferred from unequal dimensions, but since in rare cases a matrix with equal dimensions may still be an incidence matrix, an additional argument twomode can be specified to override this heuristic.

This information is usually already embedded in {igraph}, {tidygraph}, and {network} objects.

See Also

Other manipulations: add, grab, reformat, transform()

Examples

Run this code
test <- data.frame(from = c("A","B","B","C","C"),
                   to = c("I","G","I","G","H"))
as_edgelist(test)
as_matrix(test)
as_igraph(test)
as_tidygraph(test)
as_network(test)
as_graphAM(test)

Run the code above in your browser using DataLab