matrix_to_edge_list: Convert an connectivity matrix to an edge list

View source: R/matrix_to_edge_list.R

matrix_to_edge_listR Documentation

Convert an connectivity matrix to an edge list

Description

Converts a connectivity matrix to an edge list. This function allows to create the same edge list as the one obtained with create_edge_list().

Usage

matrix_to_edge_list(x, all = FALSE)

Arguments

x

a matrix object. The connectivity matrix to be converted in an edge list.

all

a logical value. If FALSE (default), removes missing edges.

Value

A data.frame with two (or three) columns:

  • from: label of one of the two nodes of the edge

  • to: label of the other node of the edge

  • edge: 0 (no edge) or 1 (edge). This column is returned only if all = TRUE.

Examples

library("chessboard")

# Two-dimensional sampling ----
sites_infos <- expand.grid("transect" = 1:3, "quadrat" = 1:5)
sites_infos

nodes <- create_node_labels(data     = sites_infos, 
                            transect = "transect", 
                            quadrat  = "quadrat")

edges <- create_edge_list(nodes, method = "pawn", directed = TRUE)

conn_matrix <- connectivity_matrix(edges)

# Convert back to edge list ----
new_edges <- matrix_to_edge_list(conn_matrix)
new_edges

# Check ----
identical(edges, new_edges)

chessboard documentation built on Oct. 14, 2023, 9:15 a.m.