These functions coerce objects into different objects by extracting and translating the information contained in the original object:

  • as_edgelist() coerces the object into an edgelist, as data frames or tibbles.

  • as_nodelist() coerces the object into a nodelist, as a data frame or tibble.

  • as_changelist() coerces the object into a changelist, as a data frame or tibble.

  • as_infolist() coerces the object into a list of network-level information, such as the names of the nodes and ties, if not given in the nodelist or edgelist.

  • as_matrix() coerces the object into an adjacency (one-mode/unipartite) or incidence (two-mode/bipartite) matrix.

These coercions are extractive in the sense that they will lose any information that cannot be contained in the target format. for example, as_matrix() will lose any information about edge attributes, such as edge types or weights.

as_nodelist(.data)

as_changelist(.data)

as_edgelist(.data, twomode = FALSE)

as_infolist(.data)

as_matrix(.data, twomode = NULL)

Arguments

.data

An object of a {manynet}-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.

Value

The currently implemented coercions or translations are:

              data.frame diff_model igraph matrix network network.goldfish
as_changelist                            *              *
as_edgelist            *                 *      *       *                *
as_infolist                              *              *
as_matrix              *          *      *      *       *                *
as_nodelist                              *              *
              siena stocnet tbl_graph
as_changelist             *         *
as_edgelist       *       *         *
as_infolist               *         *
as_matrix         *       *         *
as_nodelist               *         *

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.

See also

Other coercions: coerce_graph

Examples

test <- data.frame(from = c("A","B","B","C","C"), to = c("I","G","I","G","H"))
as_edgelist(test)
#>   from to
#> 1    A  I
#> 2    B  G
#> 3    B  I
#> 4    C  G
#> 5    C  H
as_matrix(test)
#>   G H I
#> A 0 0 1
#> B 1 0 1
#> C 1 1 0
as_igraph(test)
#> IGRAPH 30f06e1 DN-- 6 5 -- 
#> + attr: name (v/c)
#> + edges from 30f06e1 (vertex names):
#> [1] A->I B->G B->I C->G C->H
as_tidygraph(test)
#> # A labelled, directed network of 6 nodes and 5 arcs
#> 
#> ── Nodes 
#> # A tibble: 6 × 1
#>   name 
#>   <chr>
#> 1 A    
#> 2 B    
#> 3 C    
#> 4 I    
#> 5 G    
#> 6 H    
#> 
#> ── Ties 
#> # A tibble: 5 × 2
#>    from    to
#>   <int> <int>
#> 1     1     4
#> 2     2     5
#> 3     2     4
#> 4     3     5
#> 5     3     6
#> 
as_network(test)
#>  Network attributes:
#>   vertices = 6 
#>   directed = FALSE 
#>   hyper = FALSE 
#>   loops = FALSE 
#>   multiple = FALSE 
#>   bipartite = 3 
#>   total edges= 5 
#>     missing edges= 0 
#>     non-missing edges= 5 
#> 
#>  Vertex attribute names: 
#>     vertex.names 
#> 
#> No edge attributes