net_to_mat | R Documentation |
This function generates a contingency table from a two- or three-column
data.frame
, where each row represents the interaction between two
nodes (e.g., site and species) and an optional third column indicates
the weight of the interaction (if weight = TRUE
).
net_to_mat(
net,
weight = FALSE,
squared = FALSE,
symmetrical = FALSE,
missing_value = 0
)
net |
A two- or three-column |
weight |
A |
squared |
A |
symmetrical |
A |
missing_value |
The value to assign to pairs of nodes not present
in |
A matrix
with the first nodes (from the first column of net
)
as rows and the second nodes (from the second column of net
) as columns.
If squared = TRUE
, the rows and columns will have the same number of
elements, corresponding to the unique union of objects in the first and
second columns of net
. If squared = TRUE
and symmetrical = TRUE
,
the matrix will be forced to be symmetrical based on the upper triangular
part of the matrix.
Maxime Lenormand (maxime.lenormand@inrae.fr)
Pierre Denelle (pierre.denelle@gmail.com)
Boris Leroy (leroy.boris@gmail.com)
For more details illustrated with a practical example, see the vignette: https://biorgeo.github.io/bioregion/articles/a2_matrix_and_network_formats.html.
Associated functions: mat_to_net
net <- data.frame(
Site = c(rep("A", 2), rep("B", 3), rep("C", 2)),
Species = c("a", "b", "a", "c", "d", "b", "d"),
Weight = c(10, 100, 1, 20, 50, 10, 20)
)
mat <- net_to_mat(net, weight = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.