igraph_from_matrices {ILSM} | R Documentation |
Transforming matrices into network
Description
Two matrices contain three groups of tropical level species. A multilayer network can be transformed from existing matrices data.
Usage
igraph_from_matrices(mat1, mat2, isDirected1 = TRUE, isDirected2 = TRUE)
Arguments
mat1 |
A numeric matrix(or data.frame) representing interactions between two groups of species.Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. |
mat2 |
A numeric matrix(or data.frame) representing interactions between two groups of species.Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. |
isDirected1 |
Logical. Whether the interaction between the two groups of species in |
isDirected2 |
Logical. Whether the interaction between the two groups of species in |
Details
mat1 and mat2
The type of inputting is data frame or matrix, please make sure the row of mat1
and mat2
correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.
Try to make the rows of both matrices have the same attributes. Or we default:
When the two matrices can have different numbers of rows:
(1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.
(2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.
When the two matrices can have the same numbers of rows:
No matter how the row names of the two matrices are arranged, as long as the row names are exactly the same; But we don't handle matrices with empty row names (the function will give an error).
The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!
The columns of mat1
and mat2
could be empty. If empty, the function also defaults to the suggested assignment.
Value
Return a network of type "igraph".
Examples
set.seed(12)
MAT <- build_net(11,22,21,0.2,asmatrices=TRUE)
MAT[[1]]
tmat<-t(MAT[[3]])
colnames(tmat)<-NULL
igraph_from_matrices(MAT[[3]],MAT[[4]])
M <- igraph_from_matrices(tmat,MAT[[4]])
M