Created
March 17, 2014 06:05
-
-
Save timcameron/9594660 to your computer and use it in GitHub Desktop.
OECD data into R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(XML2R) | |
#Autonomous pension fund assets | |
file <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/PNN_NEW/APLANS.ADEF.PF.1000.USD.AUS/OECD?startTime=2010&endTime=2012" | |
obs <- XML2Obs(file) | |
# Rename observations so we can 'recycle' country labels to time/value | |
nms <- names(obs) | |
nms[grepl("SeriesKey//Value$", nms)] <- "root" | |
nms[grepl("Obs//Time$", nms)] <- "root//time" | |
nms[grepl("Obs//ObsValue$", nms)] <- "root//value" | |
names(obs) <- nms | |
obs <- add_key(obs, parent="root", recycle="value", key.name="country") | |
tabs <- collapse_obs(obs) | |
# There has to be a more graceful way to combine value/time into the same data.frame | |
# I might work on a new XML2R verb to 'squish' two 'siblings' into the same observation | |
dat <- data.frame(tabs[["root//value"]][,c("value", "country")], | |
time = tabs[["root//time"]][,c("XML_value")], | |
stringsAsFactors = FALSE) | |
dat$value2 <- round(as.numeric(dat$value)) | |
head(dat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment