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
).
Arguments
- net
A two- or three-column
data.frame
where each row represents the interaction between two nodes (e.g., site and species), with an optional third column indicating the weight of the interaction.- weight
A
logical
value indicating whether the weight column should be considered.- squared
A
logical
value indicating whether the output matrix should be square (i.e., containing the same nodes in rows and columns).- symmetrical
A
logical
value indicating whether the resulting matrix should be symmetrical. This applies only ifsquared = TRUE
. Note that different weights associated with opposite pairs already present innet
will be preserved.- missing_value
The value to assign to pairs of nodes not present in
net
. Defaults to0
.
Value
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.
See also
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
Author
Maxime Lenormand (maxime.lenormand@inrae.fr)
Pierre Denelle (pierre.denelle@gmail.com)
Boris Leroy (leroy.boris@gmail.com)