我最近有兴趣通过JSON检索R中的数据。具体来说,我希望能够通过IMF访问数据。我对JSON几乎一无所知,所以我将分享我迄今为止所知道的以及我所取得的成就。
我浏览了他们的JSON网页,这有点帮助。它给了我起点URL。这是网页; http://datahelp.imf.org/knowledgebase/articles/667681-using-json-restful-web-service
我设法下载(使用GET()
和fromJSON()
函数)一些列表,这些列表非常笨重。我对"呼叫"是成功的,但我不能为我的生活获得实际数据。到目前为止,我一直在尝试在"内容"上使用rawToChar()
功能。数据,但我几乎卡在那里。
如果有的话,我设法创建包含代码的数据框,我认为这些代码将在JSON链接中的某处使用。这就是我所拥有的。
all.imf.data = fromJSON("http://dataservices.imf.org/REST/SDMX_JSON.svc/Dataflow/")
str(all.imf.data)
#all.imf.data$Structure$Dataflows$Dataflow$Name[[2]] #for the catalogue of sources
catalogue1 = cbind(all.imf.data$Structure$Dataflows$Dataflow$KeyFamilyRef,
all.imf.data$Structure$Dataflows$Dataflow$Name[[2]])
catalogue1 = catalogue1[,-2] # catalogue of all the countries
data.structure = fromJSON("http://dataservices.imf.org/REST/SDMX_JSON.svc/DataStructure/IFS")
info1 = data.frame(data.structure$Structure$Concepts$ConceptScheme$Concept[,c(1,4)])
View(data.structure$Structure$CodeLists$CodeList$Description)
str(data.structure$Structure$CodeLists$CodeList$Code)
#Units
units = data.structure$Structure$CodeLists$CodeList$Code[[1]]
#Countries
countries = data.frame(data.structure$Structure$CodeLists$CodeList$Code[[3]])
countries = countries[,-length(countries)]
#Series Codes
codes = data.frame(data.structure$Structure$CodeLists$CodeList$Code[[4]])
codes = codes[,-length(codes)]
# all.imf.data # JSON from the starting point, provided on the website
# catalogue1 # data frame of all the data bases, International Financial Statistics, Government Financial Statistics, etc.
# codes # codes for the specific data sets (GDP, Current Account, etc).
# countries # data frame of all the countries and their ISO codes
# data.structure # large list, with starting URL and endpoint "IFS". Ideally, I want to find some data set somewhere within this data base.
"info1" # looks like parameters for retrieving the data (for instance, dates, units, etc).
# units # data frame that indicates the options for units
我想就如何检索任何数据提出一些建议,就像GDP(PPP)这样简单的一年。我一直关注R博客中的一篇文章(检索欧盟数据库中的数据),但我不能复制IMF的程序。我觉得我接近检索有用的东西,但我不能完全到达那里。鉴于我的数据框包含数据库的名称,系列和系列的代码,我认为只是要弄清楚如何构建适当的URL来获取数据,但我可能是错的。
在数据框codes
中提供了我认为的数据集的代码。有没有办法为BK_DB_BP6_USD
的美国拨打电话号码,即#34;国际收支,资本账户,总额,借记卡等等。" ?我应该如何在R的背景下这样做呢?