graph_to_df: Convert a graph into a edge list data.frame

Description Usage Arguments Details Value Author(s) Examples

View source: R/graph_to_df.R

Description

The function converts a graph into a edge list data.frame

Usage

1
graph_to_df(graph, weight = TRUE)

Arguments

graph

A graph object of class igraph

weight

Logical. If TRUE (default), then the column 'link' of the output data.frame contains the weights of the links. If FALSE, it contains only 0 and 1.

Details

The 'graph' nodes must have names. Links must have weights if 'weight = TRUE'.

Value

An object of class data.frame with a link ID, the origin nodes ('from') and arrival nodes ('to') and the link value ('link')(weighted or binary)

Author(s)

P. Savary

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(pts_pop_ex)
suppressWarnings(mat_geo <- mat_geo_dist(pts_pop_ex,
                 ID = "ID",
                 x = "x",
                y = "y"))
g1 <- gen_graph_thr(mat_w = mat_geo,
                    mat_thr = mat_geo,
                    thr = 20000)
g1_df <- graph_to_df(g1,
                     weight = TRUE)

graph4lg documentation built on March 16, 2021, 5:09 p.m.