从URL读取一个表,并将其作为数据框保存

从URL读取一个表,并将其作为数据框保存,r,url,dataframe,read.table,R,Url,Dataframe,Read.table,我对函数read.table有问题。我想从url读取一个表,并将其作为数据帧保存在R中。网址是: 我编写了以下代码: 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/dat

我对函数read.table有问题。我想从url读取一个表,并将其作为数据帧保存在R中。网址是:

我编写了以下代码:

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"))
我还尝试将文档作为txt下载,并将其保存在mi PC中。但是生成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)
库(RCurl)

a这里是另一种使用
rvest
而不是
RCurl
的解决方案。我不想判断哪个包“更好”,只是想显示一个附加选项,尽管在您的简单示例中,
rvest
似乎更详细,您需要选择Orgadget来识别所需的节点(如果我错了,请任何人纠正我,代码可以缩短)

库(rvest)
表%
html_文本(“p”)%>%
{read.table(text=,header=T)}

很高兴它有帮助!
library(RCurl)
a <- getURL('https://datanalytics.com/uploads/datos_treemap.txt')
b <- read.table(text=a, header = TRUE)
library(rvest)

table <- read_html("https://datanalytics.com/uploads/datos_treemap.txt") %>% 
         html_text("p") %>% 
         { read.table(text = ., header = T) }