如何在R中读取.edges文件?

问题描述 投票:1回答:1

我从网络存储库(http://networkrepository.com/actor-movie.php)下载了一个网络对象。但是我无法使用igraph :: read.graph在R中加载此.edges文件,但出现以下错误:

dat <- read.graph("actor-movie.edges")

Error in read.graph.edgelist(file, ...) : 
  At foreign.c:101 : parsing edgelist file failed, Parse error

有人知道如何在R中加载此网络吗?

r igraph
1个回答
0
投票

I 认为 igraph::read_graph的错误是由于分隔符引起的-在文件中逗号分隔,但该函数需要空格。但是,我们可以使用标准导入工具将这些文件作为数据帧读取。然后可以使用igraph函数来形成图形。

# download
pth <- "http://nrvis.com/download/data/misc/actor-movie.zip"
download.file(pth, destfile = "actor-movie.zip")

# see file names
unzip("actor-movie.zip", list = TRUE)

# unzip
unz <- unzip("actor-movie.zip", "actor-movie.edges")

# quick look : looks like edge list
readLines(unz, n=10)

# skip first line to avoid % bipartite unweighted" 
dat <- read.table(unz, skip=1, sep=",")

# look
head(dat)
str(dat)

# load as a graph
library(igraph)

g <- graph_from_data_frame(dat)
g
© www.soinside.com 2019 - 2024. All rights reserved.