Converts a data.frame to a distance matrix.

df_to_matrix(data, lower = TRUE, upper = TRUE, diag = TRUE, na_to_zero = TRUE)

Arguments

data

a data.frame with the following three columns: from (the first site), to (the second site) and distance (the value of the link between two sites). The output of the function distance_along().

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.

Value

A matrix of dimensions m x n, where m is the number of sites (from) and n is the number of sites (to).

Examples

# Add an example ----