I use the asnipe
package to create networks from group-by-individual matrix, but then, I need to convert it as an adjacency matrix.
To do so, I thought about using the functions included in igraph
such as get.adjacency
, but it returns a non-weighted matrix, where all the associations only take 1 as a value.
For instance, if we consider the following dataset:
data <- read.table(text = " A B C D E
1 1 1 0 0 0
2 1 1 0 0 0
3 1 1 0 0 0
4 1 1 0 0 0
5 0 0 1 1 1
6 0 0 1 1 1
7 0 0 1 1 1
8 0 0 1 1 1
9 1 1 1 1 1", header = TRUE)
Which gives the following graph:
network <- get_network(association_data = data, data_format = "GBI")
# Generating 5 x 5 matrix
library(igraph)
net <- graph.adjacency(network, mode = "undirected", weighted = TRUE, diag = FALSE)
I would expect to get a matrix like this one:
A B C D E
A . 5 1 1 1
B 5 . 1 1 1
C 1 1 . 5 5
D 1 1 5 . 5
E 1 1 5 5 .
But I get this:
get.adjacency(net)
# 5 x 5 sparse Matrix of class "dgCMatrix"
A B C D E
A . 1 1 1 1
B 1 . 1 1 1
C 1 1 . 1 1
D 1 1 1 . 1
E 1 1 1 1 .
This data set is an example, the real data contains thousands of lines, excluding any possibility to do it manually. Thank you a lot by advance!