我对函数 read.table 有疑问。我想从 url 中读取一个表,并将其作为数据框保存在 R 中。网址是: https://datanalytics.com/uploads/datos_treemap.txt
我写了这段代码:
library(RCurl)
a <- getURL('https://datanalytics.com/uploads/datos_treemap.txt')
b = read.table(a, sep="\t ", header = TRUE, nrows=3)
download.file("https://datanalytics.com/uploads/datos_treemap.txt","/mnt/M/Ana/R/datos_treemap.txt",method = c("wget"))
但我无法将数据保留为数据帧,这会导致以下错误:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file...
No such file or directory
我也试过把文档下载成txt格式,保存在小米PC里。但是 generate txt 生成一个向量而不是一个表(所有结果都在一个 unic 行中)。我写的代码是:
download.file("https://datanalytics.com/uploads/datos_treemap.txt","/mnt/M/Ana/R/datos_treemap.txt",method = c("wget"))
我做错了什么?
最佳答案
library(RCurl)
a <- getURL('https://datanalytics.com/uploads/datos_treemap.txt')
b <- read.table(text=a, header = TRUE)
关于r - 如何从 URL 读取表格并将其保存为数据框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47217562/