从邻接矩阵不生成边

时间:2021-05-07 12:17:51

标签: r igraph

当从 graph_from_adjacency_matrix() 调用 igraph 时,我根本没有得到任何边缘。

library(igraph)

set.seed(42)

# data = read.table("sequences_distancematrix.out", row.names = 1, stringsAsFactors = FALSE, header = TRUE)
data = read.table("https://pastebin.com/raw/UWt56tfh", row.names = 1, stringsAsFactors = FALSE, header = TRUE)


dismat = data.matrix(data)

# build the graph object
network <- graph_from_adjacency_matrix(dismat, mode = "undirected")

但是在检查网络时没有边缘:

> print_all  (network)
IGRAPH f4f6666 UN-- 46 0 -- 
+ attr: name (v/c)

我认为这可能是因为 igraph 不接受低于 0 的双精度值,所以 x10 矩阵中的所有内容但结果相同

距离矩阵:https://pastebin.com/UWt56tfh

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

  • 如果您想要加权边:
(network <- graph_from_adjacency_matrix(dismat, mode = "undirected", weighted = TRUE))
  • 如果您想要未加权的边:
(network <- graph_from_adjacency_matrix(dismat > 0, mode = "undirected"))

答案 1 :(得分:0)

我不确定您是如何尝试将所有内容乘以 10 的,但这对我有用。

library(igraph)

data <- read.table("https://pastebin.com/raw/UWt56tfh", 
                  row.names = 1, stringsAsFactors = FALSE, header = TRUE) 

dismat <- data.matrix(data)
network <-  graph_from_adjacency_matrix(dismat*10, mode = "undirected")
print_all(network)