Creates an edges weights matrix from the output of distance_euclidean().

edges_weights_matrix(distances, lower = TRUE, upper = TRUE, diag = TRUE)

Arguments

distances

a data.frame with the following three columns: from (the first node of the edge), to (the second node of the edge), and weight (the weight of the edge between the two nodes, e.g. a distance).

lower

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

upper

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

diag

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

Value

An edges weights matrix of dimensions n x n, where n is the number of nodes (sites).

Examples

# Import Adour sites ----
path_to_file <- system.file("extdata", "adour_survey_sampling.csv", 
                            package = "chessboard")
adour_sites <- read.csv(path_to_file)

# Select the 15 first sites ----
adour_sites <- adour_sites[1:15, ]

# Create node labels ----
adour_sites <- create_node_labels(adour_sites, 
                                  location = "location", 
                                  transect = "transect", 
                                  quadrat  = "quadrat")

# Convert sites to sf object (POINTS) ----
adour_sites_sf <- sf::st_as_sf(adour_sites, 
                               coords = c("longitude", "latitude"),
                               crs = "epsg:2154")

# Compute distances between pairs of sites along the Adour river ----
adour_dists <- distance_euclidean(adour_sites_sf)

# Create Edges weights matrix ----
edges_weights_matrix(adour_dists)
#>           1-1      1-2      1-3      1-4       1-5       2-1      2-2      2-3
#> 1-1     0.000 2500.469 5000.938 7501.407 10001.876  2500.469 3536.197 5591.219
#> 1-2  2500.469    0.000 2500.469 5000.938  7501.407  3536.197 2500.469 3536.197
#> 1-3  5000.938 2500.469    0.000 2500.469  5000.938  5591.219 3536.197 2500.469
#> 1-4  7501.407 5000.938 2500.469    0.000  2500.469  7907.178 5591.219 3536.197
#> 1-5 10001.876 7501.407 5000.938 2500.469     0.000 10309.698 7907.178 5591.219
#> 2-1  2500.469 3536.197 5591.219 7907.178 10309.698     0.000 2500.469 5000.938
#> 2-2  3536.197 2500.469 3536.197 5591.219  7907.178  2500.469    0.000 2500.469
#> 2-3  5591.219 3536.197 2500.469 3536.197  5591.219  5000.938 2500.469    0.000
#> 2-4  7907.178 5591.219 3536.197 2500.469  3536.197  7501.407 5000.938 2500.469
#> 2-5 10309.698 7907.178 5591.219 3536.197  2500.469 10001.876 7501.407 5000.938
#> 3-1  5000.938 5591.219 7072.395 9015.569 11182.438  2500.469 3536.197 5591.219
#> 3-2  5591.219 5000.938 5591.219 7072.395  9015.569  3536.197 2500.469 3536.197
#> 3-3  7072.395 5591.219 5000.938 5591.219  7072.395  5591.219 3536.197 2500.469
#> 3-4  9015.569 7072.395 5591.219 5000.938  5591.219  7907.178 5591.219 3536.197
#> 3-5 11182.438 9015.569 7072.395 5591.219  5000.938 10309.698 7907.178 5591.219
#>          2-4       2-5       3-1      3-2      3-3      3-4       3-5
#> 1-1 7907.178 10309.698  5000.938 5591.219 7072.395 9015.569 11182.438
#> 1-2 5591.219  7907.178  5591.219 5000.938 5591.219 7072.395  9015.569
#> 1-3 3536.197  5591.219  7072.395 5591.219 5000.938 5591.219  7072.395
#> 1-4 2500.469  3536.197  9015.569 7072.395 5591.219 5000.938  5591.219
#> 1-5 3536.197  2500.469 11182.438 9015.569 7072.395 5591.219  5000.938
#> 2-1 7501.407 10001.876  2500.469 3536.197 5591.219 7907.178 10309.698
#> 2-2 5000.938  7501.407  3536.197 2500.469 3536.197 5591.219  7907.178
#> 2-3 2500.469  5000.938  5591.219 3536.197 2500.469 3536.197  5591.219
#> 2-4    0.000  2500.469  7907.178 5591.219 3536.197 2500.469  3536.197
#> 2-5 2500.469     0.000 10309.698 7907.178 5591.219 3536.197  2500.469
#> 3-1 7907.178 10309.698     0.000 2500.469 5000.938 7501.407 10001.876
#> 3-2 5591.219  7907.178  2500.469    0.000 2500.469 5000.938  7501.407
#> 3-3 3536.197  5591.219  5000.938 2500.469    0.000 2500.469  5000.938
#> 3-4 2500.469  3536.197  7501.407 5000.938 2500.469    0.000  2500.469
#> 3-5 3536.197  2500.469 10001.876 7501.407 5000.938 2500.469     0.000

# Create Edges weights matrix (with options) ----
edges_weights_matrix(adour_dists, lower = FALSE)
#>     1-1      1-2      1-3      1-4       1-5       2-1      2-2      2-3
#> 1-1   0 2500.469 5000.938 7501.407 10001.876  2500.469 3536.197 5591.219
#> 1-2  NA    0.000 2500.469 5000.938  7501.407  3536.197 2500.469 3536.197
#> 1-3  NA       NA    0.000 2500.469  5000.938  5591.219 3536.197 2500.469
#> 1-4  NA       NA       NA    0.000  2500.469  7907.178 5591.219 3536.197
#> 1-5  NA       NA       NA       NA     0.000 10309.698 7907.178 5591.219
#> 2-1  NA       NA       NA       NA        NA     0.000 2500.469 5000.938
#> 2-2  NA       NA       NA       NA        NA        NA    0.000 2500.469
#> 2-3  NA       NA       NA       NA        NA        NA       NA    0.000
#> 2-4  NA       NA       NA       NA        NA        NA       NA       NA
#> 2-5  NA       NA       NA       NA        NA        NA       NA       NA
#> 3-1  NA       NA       NA       NA        NA        NA       NA       NA
#> 3-2  NA       NA       NA       NA        NA        NA       NA       NA
#> 3-3  NA       NA       NA       NA        NA        NA       NA       NA
#> 3-4  NA       NA       NA       NA        NA        NA       NA       NA
#> 3-5  NA       NA       NA       NA        NA        NA       NA       NA
#>          2-4       2-5       3-1      3-2      3-3      3-4       3-5
#> 1-1 7907.178 10309.698  5000.938 5591.219 7072.395 9015.569 11182.438
#> 1-2 5591.219  7907.178  5591.219 5000.938 5591.219 7072.395  9015.569
#> 1-3 3536.197  5591.219  7072.395 5591.219 5000.938 5591.219  7072.395
#> 1-4 2500.469  3536.197  9015.569 7072.395 5591.219 5000.938  5591.219
#> 1-5 3536.197  2500.469 11182.438 9015.569 7072.395 5591.219  5000.938
#> 2-1 7501.407 10001.876  2500.469 3536.197 5591.219 7907.178 10309.698
#> 2-2 5000.938  7501.407  3536.197 2500.469 3536.197 5591.219  7907.178
#> 2-3 2500.469  5000.938  5591.219 3536.197 2500.469 3536.197  5591.219
#> 2-4    0.000  2500.469  7907.178 5591.219 3536.197 2500.469  3536.197
#> 2-5       NA     0.000 10309.698 7907.178 5591.219 3536.197  2500.469
#> 3-1       NA        NA     0.000 2500.469 5000.938 7501.407 10001.876
#> 3-2       NA        NA        NA    0.000 2500.469 5000.938  7501.407
#> 3-3       NA        NA        NA       NA    0.000 2500.469  5000.938
#> 3-4       NA        NA        NA       NA       NA    0.000  2500.469
#> 3-5       NA        NA        NA       NA       NA       NA     0.000
edges_weights_matrix(adour_dists, upper = FALSE)
#>           1-1      1-2      1-3      1-4       1-5       2-1      2-2      2-3
#> 1-1     0.000       NA       NA       NA        NA        NA       NA       NA
#> 1-2  2500.469    0.000       NA       NA        NA        NA       NA       NA
#> 1-3  5000.938 2500.469    0.000       NA        NA        NA       NA       NA
#> 1-4  7501.407 5000.938 2500.469    0.000        NA        NA       NA       NA
#> 1-5 10001.876 7501.407 5000.938 2500.469     0.000        NA       NA       NA
#> 2-1  2500.469 3536.197 5591.219 7907.178 10309.698     0.000       NA       NA
#> 2-2  3536.197 2500.469 3536.197 5591.219  7907.178  2500.469    0.000       NA
#> 2-3  5591.219 3536.197 2500.469 3536.197  5591.219  5000.938 2500.469    0.000
#> 2-4  7907.178 5591.219 3536.197 2500.469  3536.197  7501.407 5000.938 2500.469
#> 2-5 10309.698 7907.178 5591.219 3536.197  2500.469 10001.876 7501.407 5000.938
#> 3-1  5000.938 5591.219 7072.395 9015.569 11182.438  2500.469 3536.197 5591.219
#> 3-2  5591.219 5000.938 5591.219 7072.395  9015.569  3536.197 2500.469 3536.197
#> 3-3  7072.395 5591.219 5000.938 5591.219  7072.395  5591.219 3536.197 2500.469
#> 3-4  9015.569 7072.395 5591.219 5000.938  5591.219  7907.178 5591.219 3536.197
#> 3-5 11182.438 9015.569 7072.395 5591.219  5000.938 10309.698 7907.178 5591.219
#>          2-4       2-5       3-1      3-2      3-3      3-4 3-5
#> 1-1       NA        NA        NA       NA       NA       NA  NA
#> 1-2       NA        NA        NA       NA       NA       NA  NA
#> 1-3       NA        NA        NA       NA       NA       NA  NA
#> 1-4       NA        NA        NA       NA       NA       NA  NA
#> 1-5       NA        NA        NA       NA       NA       NA  NA
#> 2-1       NA        NA        NA       NA       NA       NA  NA
#> 2-2       NA        NA        NA       NA       NA       NA  NA
#> 2-3       NA        NA        NA       NA       NA       NA  NA
#> 2-4    0.000        NA        NA       NA       NA       NA  NA
#> 2-5 2500.469     0.000        NA       NA       NA       NA  NA
#> 3-1 7907.178 10309.698     0.000       NA       NA       NA  NA
#> 3-2 5591.219  7907.178  2500.469    0.000       NA       NA  NA
#> 3-3 3536.197  5591.219  5000.938 2500.469    0.000       NA  NA
#> 3-4 2500.469  3536.197  7501.407 5000.938 2500.469    0.000  NA
#> 3-5 3536.197  2500.469 10001.876 7501.407 5000.938 2500.469   0
edges_weights_matrix(adour_dists, diag = FALSE)
#>           1-1      1-2      1-3      1-4       1-5       2-1      2-2      2-3
#> 1-1        NA 2500.469 5000.938 7501.407 10001.876  2500.469 3536.197 5591.219
#> 1-2  2500.469       NA 2500.469 5000.938  7501.407  3536.197 2500.469 3536.197
#> 1-3  5000.938 2500.469       NA 2500.469  5000.938  5591.219 3536.197 2500.469
#> 1-4  7501.407 5000.938 2500.469       NA  2500.469  7907.178 5591.219 3536.197
#> 1-5 10001.876 7501.407 5000.938 2500.469        NA 10309.698 7907.178 5591.219
#> 2-1  2500.469 3536.197 5591.219 7907.178 10309.698        NA 2500.469 5000.938
#> 2-2  3536.197 2500.469 3536.197 5591.219  7907.178  2500.469       NA 2500.469
#> 2-3  5591.219 3536.197 2500.469 3536.197  5591.219  5000.938 2500.469       NA
#> 2-4  7907.178 5591.219 3536.197 2500.469  3536.197  7501.407 5000.938 2500.469
#> 2-5 10309.698 7907.178 5591.219 3536.197  2500.469 10001.876 7501.407 5000.938
#> 3-1  5000.938 5591.219 7072.395 9015.569 11182.438  2500.469 3536.197 5591.219
#> 3-2  5591.219 5000.938 5591.219 7072.395  9015.569  3536.197 2500.469 3536.197
#> 3-3  7072.395 5591.219 5000.938 5591.219  7072.395  5591.219 3536.197 2500.469
#> 3-4  9015.569 7072.395 5591.219 5000.938  5591.219  7907.178 5591.219 3536.197
#> 3-5 11182.438 9015.569 7072.395 5591.219  5000.938 10309.698 7907.178 5591.219
#>          2-4       2-5       3-1      3-2      3-3      3-4       3-5
#> 1-1 7907.178 10309.698  5000.938 5591.219 7072.395 9015.569 11182.438
#> 1-2 5591.219  7907.178  5591.219 5000.938 5591.219 7072.395  9015.569
#> 1-3 3536.197  5591.219  7072.395 5591.219 5000.938 5591.219  7072.395
#> 1-4 2500.469  3536.197  9015.569 7072.395 5591.219 5000.938  5591.219
#> 1-5 3536.197  2500.469 11182.438 9015.569 7072.395 5591.219  5000.938
#> 2-1 7501.407 10001.876  2500.469 3536.197 5591.219 7907.178 10309.698
#> 2-2 5000.938  7501.407  3536.197 2500.469 3536.197 5591.219  7907.178
#> 2-3 2500.469  5000.938  5591.219 3536.197 2500.469 3536.197  5591.219
#> 2-4       NA  2500.469  7907.178 5591.219 3536.197 2500.469  3536.197
#> 2-5 2500.469        NA 10309.698 7907.178 5591.219 3536.197  2500.469
#> 3-1 7907.178 10309.698        NA 2500.469 5000.938 7501.407 10001.876
#> 3-2 5591.219  7907.178  2500.469       NA 2500.469 5000.938  7501.407
#> 3-3 3536.197  5591.219  5000.938 2500.469       NA 2500.469  5000.938
#> 3-4 2500.469  3536.197  7501.407 5000.938 2500.469       NA  2500.469
#> 3-5 3536.197  2500.469 10001.876 7501.407 5000.938 2500.469        NA