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_globallist() coerces the object into a globallist, 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. If the network is a cognitive social structure (i.e. the edgelist contains a 'by' column indicating who reported/recorded each tie), as_matrix() returns a three-dimensional array instead, with dimensions for senders, receivers, and reporters.

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_globallist(.data)

as_matrix(.data, twomode = NULL)

Arguments

.data

An object of a {manynet}-consistent class:

  • adjacency or incidence matrix from {base} R

  • edgelist data.frame from {base} R or tbl/tbl_df from {tibble}

  • stocnet stocnet, from the {manynet} package

  • igraph igraph, from the {igraph} package

  • network network, from the {network} package

  • tidygraph 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_globallist                            *
as_infolist                              *              *
as_matrix              *          *      *      *       *                *
as_nodelist                              *              *
              siena stocnet tbl_graph
as_changelist             *         *
as_edgelist       *       *         *
as_globallist             *
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 5b946a9 DN-B 6 5 -- 
#> + attr: name (v/c), type (v/l)
#> + edges from 5b946a9 (vertex names):
#> [1] A->I B->G B->I C->G C->H
as_tidygraph(test)
#> # A labelled, two-mode network of 3 nodes and 3 nodes and 5 ties
#> 
#> ── Nodes 
#> # A tibble: 6 × 2
#>   name  type 
#>   <chr> <lgl>
#> 1 A     FALSE
#> 2 B     FALSE
#> 3 C     FALSE
#> 4 I     TRUE 
#> 5 G     TRUE 
#> 6 H     TRUE 
#> 
#> ── 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