The as_
functions in {migraph}
coerce objects
between several common classes of social network objects.
These include:
edgelists, as data frames or tibbles
adjacency and incidence matrices
{igraph}
graph
objects
{tidygraph}
tbl_graph
objects
{network}
network
objects
as_edgelist(object, weight = FALSE)as_matrix(object, weight = FALSE)
as_igraph(object, weight = FALSE, twomode = FALSE)
as_tidygraph(object, twomode = FALSE)
as_network(object)
A data frame edgelist, matrix, igraph, tidygraph, or network object.
An option to override the heuristics for distinguishing weighted networks. By default FALSE.
An option to override the heuristics for distinguishing incidence from adjacency matrices. By default FALSE.
The currently implemented coercions or translations are:
to/from | edgelists | matrices | igraph | tidygraph | network |
edgelists (data frames) | X | X | X | X | |
matrices | X | X | X | X | X |
igraph | X | X | X | X | X |
tidygraph | X | X | X | X | X |
network | X | X | X | X | X |
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.
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.
# NOT RUN {
test <- data.frame(id1 = c("A","B","B","C","C"),
id2 = c("I","G","I","G","H"))
as_matrix(test)
as_igraph(test)
as_tidygraph(test)
as_network(test)
# }
Run the code above in your browser using DataLab