Skip to contents

This function creates 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) from a contingency table (sites as rows and species as columns for example).

Usage

mat_to_net(
  mat,
  weight = FALSE,
  remove_zeroes = TRUE,
  include_diag = TRUE,
  include_lower = TRUE
)

Arguments

mat

a contingency table (i.e. matrix).

weight

a boolean indicating if the value are weights.

remove_zeroes

a boolean determining whether interactions with weight equal to 0 should be removed from the output.

include_diag

a boolean indicating whether the diagonal should be included in the output. Only for squared matrix.

include_lower

a boolean indicating whether the lower triangular matrix should be included in the output. Only for squared matrix.

Value

A data.frame where each row represents the interaction between two nodes and an optional third column indicating the weight of the interaction.

See also

Author

Maxime Lenormand (maxime.lenormand@inrae.fr)
Pierre Denelle (pierre.denelle@gmail.com)
Boris Leroy (leroy.boris@gmail.com)

Examples

mat <- matrix(sample(1000, 50), 5, 10)
rownames(mat) <- paste0("Site", 1:5)
colnames(mat) <- paste0("Species", 1:10)

net <- mat_to_net(mat, weight = TRUE)