net_to_mat {bioregion} | R Documentation |
Create a contingency table from a data.frame
Description
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
).
Usage
net_to_mat(
net,
weight = FALSE,
squared = FALSE,
symmetrical = FALSE,
missing_value = 0
)
Arguments
net |
a two- or three-columns |
weight |
a |
squared |
a |
symmetrical |
a |
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(s)
Maxime Lenormand (maxime.lenormand@inrae.fr), Pierre Denelle (pierre.denelle@gmail.com) and Boris Leroy (leroy.boris@gmail.com)
See Also
Examples
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)