我在尝试从欧盟统计局下载批量数据时遇到了一些问题,希望你能帮助我。我的代码基于这个post。
library(devtools)
require(devtools)
install_github("rsdmx", "opensdmx")
require(rsdmx)
# Make a temporary file (tf) and a temporary folder (tdir)
tf <- tempfile(tmpdir = tdir <- tempdir())
## Download the zip file
download.file("http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&file=data%2Frd_e_gerdsc.sdmx.zip", tf)
## Unzip it in the temp folder
test <- unzip(tf, exdir = tdir)
sdmx <- readSDMX(test)
stats <- as.data.frame(sdmx)
head(stats)我收到这个警告,数据帧是空的:
Warning message:
In if (attr(regexpr("<!DOCTYPE html>", content), "match.length") == :
the condition has length > 1 and only the first element will be used发布于 2015-06-01 19:08:15
在欧盟统计局中,提取的结果由两个独立的XML文件组成:
DSD (data structure definition,数据结构定义),描述dataset本身的SDMX数据集。
根据您的代码,尝试如下所示:
testfile <- test[2] #path for the dataset
sdmx <- readSDMX(testfile, isURL = FALSE) # isURL = FALSE (to read a local file)
stats <- as.data.frame(sdmx)
head(stats)注意:调用as.data.frame可能需要一些时间才能完成,具体取决于数据集的大小。我一直在执行更多的测试,以便进一步提高读取大型SDMX数据集的性能。
您的用例非常有趣,我将把它添加到rsdmx documentation中,因为它展示了如何使用欧盟统计局批量下载服务和rsdmx。
希望这能有所帮助!
https://stackoverflow.com/questions/30563273
复制相似问题