Skip to content

Instantly share code, notes, and snippets.

@HughParsonage
Created January 7, 2016 02:47
Show Gist options
  • Save HughParsonage/cd505181c962c32db1f0 to your computer and use it in GitHub Desktop.
Save HughParsonage/cd505181c962c32db1f0 to your computer and use it in GitHub Desktop.
Using ABS SDMX including metadata
library(rsdmx)
library(data.table)
library(dplyr)
res_dwelling_values_metadata <-
readSDMX("http://stat.abs.gov.au/restsdmx/sdmx.ashx/GetDataStructure/RES_DWEL_ST/ABS")
recode_res_dwelling_values <- function(DT, colname){
cls <- slot(res_dwelling_values_metadata, "codelists")
codelists <- sapply(slot(cls, "codelists"), function(x) slot(x, "id"))
colname.code <-
as.data.frame(slot(res_dwelling_values_metadata, "codelists"),
codelistId = codelists[grep(colname, codelists)]) %>%
as.data.table %>%
select(id, label.en) %>%
setnames(old = "label.en", paste0("label_", colname))
merge(DT, colname.code, by.x = colname, by.y = "id")
}
res_dwelling_values <-
readSDMX("http://stat.abs.gov.au/restsdmx/sdmx.ashx/GetData/RES_DWEL_ST/1+2+3+4+5.0+1+2+3+4+5+6+7+8.Q/ABS?startTime=2011&endTime=2015") %>%
as.data.frame %>%
recode_res_dwelling_values("ASGS_2011") %>%
recode_res_dwelling_values("MEASURE") %>%
recode_res_dwelling_values("FREQUENCY") %>%
data.table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment