This function creates a contingency table from a two- or three-columns
data.frame
where each row represents the interaction between two
nodes (site and species for example) and an optional third column indicating
the weight of the interaction (if weight = TRUE
).
Arguments
- net
a two- or three-columns
data.frame
where each row represents the interaction between two nodes (site and species for example) and an optional third column indicating the weight of the interaction.- weight
a
boolean
indicating if the weight should be considered- squared
a
boolean
indicating if the output matrix should but squared (same nodes in rows and columns).- symmetrical
a
boolean
indicating if the resulting matrix should be symmetrical (only ifsquared = TRUE
). Note that different weights associated with two opposite pairs already present in net will be preserved.- missing_value
the value to assign to the pairs of nodes not present in net (0 by default).
Value
A matrix
with the first nodes (first column of net
) as
rows and the second nodes (second column of net
) as columns. Note
that if squared = TRUE
the rows and columns have the same number of
elements corresponding to the concatenation of unique objects in
net
's first and second columns. If squared = TRUE
the matrix
can be forced to be symmetrical based on the upper triangular part of the
matrix.
Author
Maxime Lenormand (maxime.lenormand@inrae.fr)
Pierre Denelle (pierre.denelle@gmail.com)
Boris Leroy (leroy.boris@gmail.com)