从文本文件导入 R 中的无向图

import an undirected graph in R from text file

The output 我在 R 中读取无向图时遇到问题,我尝试将其从包含大量边(大约 1000 个)的文本文件 "graph.txt" 导入到 R,但是问题:

R 没有从文本文件中读取整个图形,它省略了大量的边 我按照我在 R 教程中找到的步骤和本网站上的相关先前问题进行了操作,但我无法修改它。

graph.txt 看起来像:

383 886 
777 915 
793 335 
386 492 
649 421 
362 27 
690 59 
763 926 
540 426 
172 736 
211 368 
567 429 
782 530

以及我使用的函数:

library("igraph")
dd<-scan("graph.txt")
gg<-read_graph("graph.txt",directed=FALSE)
gg

结果如下:

... 763-- 785 326-- 984 946-- 946 326--1103 326-- 592 698--1636 326--1807
+ ... omitted several edges

任何帮助请让 R 从 txt 文件导入边的总数

提前致谢

P.S:我正在尝试仅将数据作为图表导入(不是 table 或矩阵)以使用以下函数计算图表的直径:

diameter(graph, directed = FALSE, weights = NULL)

我通常做的是先导入文件,然后将其转换为图表以确保安全。所以

library(igraph)
f <- read.table(file = "graph.txt")
edges <- c()
for (e in 1:dim(f)[1]){
  edges <- append(edges, c(f[e, 1], f[e, 2]))
}
g <- graph(edges, directed = FALSE)
g
#IGRAPH U--- 926 13 -- 
#+ edges:
#[1] 383--886 777--915 335--793 386--492 421--649  27--362  59--690 763--926 426--540 172--736
#[11] 211--368 429--567 530--782