The as_ functions in {manynet} coerce objects of any of the following common classes
of social network objects in R into the declared class:
as_igraph() coerces the object into an {igraph} graph object.
as_tidygraph() coerces the object into a {tidygraph} tbl_graph object.
as_network() coerces the object into a {network} network object.
as_graphAM() coerces the object into a graph adjacency matrix.
as_diffnet() coerces a diffusionModel (see as_diffusion())
into a {netdiffuseR} diffnet object.
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.
as_igraph(.data, twomode = FALSE)
as_tidygraph(.data, twomode = FALSE)
as_network(.data, twomode = FALSE)
as_hypergraph(.data)
as_graphAM(.data, twomode = NULL)
as_diffnet(.data, twomode = FALSE)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
Logical option used to override heuristics for distinguishing incidence (two-mode/bipartite) from adjacency (one-mode/unipartite) networks. By default FALSE.
The currently implemented coercions or translations are:
data.frame default diff_model diffnet hypergraph igraph list
as_diffnet *
as_graphAM *
as_hypergraph * *
as_igraph * * * *
as_network * * *
as_tidygraph * * * * *
matrix network network.goldfish networkDynamic siena sienadata
as_diffnet
as_graphAM *
as_hypergraph
as_igraph * * * * * *
as_network * * * * * *
as_tidygraph * * * * * *
stocnet tbl_graph
as_diffnet
as_graphAM
as_hypergraph
as_igraph * *
as_network * *
as_tidygraph * *as_hypergraph() returns a 'hypergraph' object of the {HyperG} package,
which is a sparse incidence matrix of hyperedges by nodes,
and as_stocnet() reads one.
A network that is not a hypergraph is reformatted as one first,
as by to_hypergraph().
A 'hypergraph' object holds which nodes each hyperedge has and their
names, and nothing else, so weights, attributes, directions,
and times are not carried.
Neither function needs {HyperG} to be installed.
Note that is_hypergraph() marks a network of any class that holds
hyperedges, of which a 'stocnet' object holds the most
(see the Hypergraphs section of make_stocnet()).
Other coercions:
coerce_list,
coerce_matrix,
coerce_stocnet
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 7dbd21d UN-B 6 5 --
#> + attr: name (v/c), type (v/l)
#> + edges from 7dbd21d (vertex names):
#> [1] A--I B--G B--I C--G C--H
as_tidygraph(test)
#> # A tbl_graph: 6 nodes and 5 edges
#> #
#> # An unrooted tree
#> #
#> # Node Data: 6 × 2 (active)
#> name type
#> <chr> <lgl>
#> 1 A FALSE
#> 2 B FALSE
#> 3 C FALSE
#> 4 I TRUE
#> 5 G TRUE
#> 6 H TRUE
#> #
#> # Edge Data: 5 × 2
#> from to
#> <int> <int>
#> 1 1 4
#> 2 2 5
#> 3 2 4
#> # ℹ 2 more rows
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
as_hypergraph(create_ring(4))
#> $M
#> 4 x 4 sparse Matrix of class "dgCMatrix"
#> 1 2 3 4
#> [1,] 1 1 . .
#> [2,] . 1 1 .
#> [3,] . . 1 1
#> [4,] 1 . . 1
#>
#> attr(,"class")
#> [1] "hypergraph"