connectivity_matrix function

Create a connectivity matrix from an edge list

Create a connectivity matrix from an edge list

Converts an edge list to an connectivity matrix (also known as adjacency matrix).

connectivity_matrix( edges, lower = TRUE, upper = TRUE, diag = TRUE, na_to_zero = TRUE )

Arguments

  • edges: a data.frame with the following two columns: from (the first node of the edge) and to (the second node of the edge). The output of the functions create_edge_list() or append_edge_lists().

  • lower: a logical value. If TRUE (default), keep values in the lower triangle of the matrix. Otherwise they will be replaced by NA

    (or 0).

  • upper: a logical value. If TRUE (default), keep values in the upper triangle of the matrix. Otherwise they will be replaced by NA

    (or 0).

  • diag: a logical value. If TRUE (default), keep values in the diagonal of the matrix. Otherwise they will be replaced by NA

    (or 0).

  • na_to_zero: a logical value. If TRUE (default), missing edges are coded as 0. Otherwise they will be coded as NA.

Returns

A connectivity matrix of dimensions n x n, where n is the number of nodes.

Examples

# Import Adour sites ---- path_to_file <- system.file("extdata", "adour_survey_sampling.csv", package = "chessboard") adour_sites <- read.csv(path_to_file) # Select first location ---- adour_sites <- adour_sites[adour_sites$"location" == 1, ] # Create node labels ---- adour_nodes <- create_node_labels(data = adour_sites, location = "location", transect = "transect", quadrat = "quadrat") # Find edges with 1 degree of neighborhood (pawn method) ---- adour_edges <- create_edge_list(adour_nodes, method = "pawn", directed = TRUE) # Get connectivity matrix ---- connectivity_matrix(adour_edges) # Get connectivity matrix ---- connectivity_matrix(adour_edges, na_to_zero = FALSE)
  • Maintainer: Nicolas Casajus
  • License: GPL (>= 2)
  • Last published: 2023-10-14