Round-trip conversion is not guaranteed currently. Conversion to data.frame preserves edge attributes and vertex names, but the other vertex attributes are lost, and internal vertex IDs may change.
Usage
as_igraph(x, ...)
# Default S3 method
as_igraph(x, ...)
# S3 method for class 'matrix'
as_igraph(x, ...)
# S3 method for class 'data.frame'
as_igraph(x, ...)
# S3 method for class 'igraph_ptr'
as.data.frame(x, ...)
# S3 method for class 'igraph_ptr'
as.matrix(x, ...)
Value
as_igraph()
returns an igraph_ptr object.
as.data.frame()
returns an edge list in data.frame format,
which may include additional columns for edge attributes.
as.matrix()
returns an edge list in matrix format.
See also
graph_from_symbolic_edgelist()
, graph_from_edgelist()
,
graph_from_data_frame()
, graph_create()
for underlying functions.
Examples
edges = seq_len(6L)
g1 = as_igraph(edges)
edgelist = as.matrix(g1) |> print()
#> [,1] [,2]
#> [1,] 1 2
#> [2,] 3 4
#> [3,] 5 6
g2 = as_igraph(edgelist)
g3 = as_igraph(as.data.frame(g2)) |> print()
#> $V tibble [6 × 1] (S3: tbl_df/tbl/data.frame)
#> $ name: int [1:6] 1 2 3 4 5 6
#> # A tibble: 3 × 2
#> from to
#> <int> <int>
#> 1 1 2
#> 2 3 4
#> 3 5 6