df_to_pw_mat: Convert an edge-list data.frame into a pairwise matrix

View source: R/df_to_pw_mat.R

df_to_pw_matR Documentation

Convert an edge-list data.frame into a pairwise matrix

Description

The function converts an edge-list data.frame into a symmetric pairwise matrix

Usage

df_to_pw_mat(data, from, to, value)

Arguments

data

An object of class data.frame

from

A character string indicating the name of the column with the ID of the origins

to

A character string indicating the name of the column with the ID of the arrivals

value

A character string indicating the name of the column with the values corresponding to each pair

Details

The matrix is a symmetric matrix. Be careful, you shall not provide a data.frame with different values corresponding to the pair 1-2 and 2-1 as an example. Ideally, for a complete matrix, data should have n(n-1)/2 rows if values are computed between n objects.

Value

A pairwise matrix

Author(s)

P. Savary

Examples

data(pts_pop_simul)
suppressWarnings(mat_geo <- mat_geo_dist(pts_pop_simul,
                 ID = "ID",
                 x = "x",
                y = "y"))
g <- gen_graph_topo(mat_w = mat_geo,
                    mat_topo = mat_geo,
                    topo = "comp")
df <- data.frame(igraph::as_edgelist(g))
df$w <- igraph::E(g)$weight
df_to_pw_mat(df, from = "X1", to = "X2", value = "w")

graph4lg documentation built on Feb. 16, 2023, 5:43 p.m.