Learn R Programming

migraph (version 0.6.6)

coercion: Coercion between migraph-consistent object classes

Description

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

  • adjacency and incidence matrices

  • edgelists (as data frames)

  • {igraph} graph objects

  • {tidygraph} tbl_graph objects

  • {network} network objects

Usage

as_matrix(object)

as_igraph(object, twomode = FALSE)

as_tidygraph(object, twomode = FALSE)

as_network(object)

Arguments

object

A data frame edgelist, matrix, igraph, tidygraph, or network object.

twomode

An option to override the heuristics for distinguishing incidence from adjacency matrices. By default FALSE.

Value

An adjacency or incidence matrix, named if possible.

An igraph graph object.

A tidygraph tbl_graph class object

A sna/network network class object

Details

Behaviour is a little different depending on the data format.

If the data frame is a 2 column edgelist, the first column will become the rows and the second column will become the columns. If the data frame is a 3 column edgelist, then the third column will be used as the cell values or tie weights.

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.

Examples

Run this code
# NOT RUN {
test <- data.frame(id1 = c("A","B","B","C","C"),
                   id2 = c("I","G","I","G","H"))
as_matrix(test)
test <- data.frame(id1 = c("A","B","B","C","C"),
                   id2 = c("I","G","I","G","H"))
as_igraph(test)
test <- data.frame(id1 = c("A","B","B","C","C"),
                   id2 = c("I","G","I","G","H"))
as_tidygraph(test)
test <- data.frame(id1 = c("A","B","B","C","C"),
                   id2 = c("I","G","I","G","H"))
as_network(test)
# }

Run the code above in your browser using DataLab