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

View source: R/graph_to_df.R

graph_to_dfR Documentation

Convert a graph into a edge list data.frame

Description

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

Usage

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

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 Feb. 16, 2023, 5:43 p.m.