Skip to content

Instantly share code, notes, and snippets.

@fontanon
Last active December 21, 2015 17:29
Show Gist options
  • Save fontanon/6341178 to your computer and use it in GitHub Desktop.
Save fontanon/6341178 to your computer and use it in GitHub Desktop.
Testing r-openspending package: Income comparision between Universities: Pablo de Olavide vs. Universidad de Granada. https://github.com/mihi-tr/r-openspending
library("ropenspending")
# Retrieving Universidad Pablo de Olavide data at openspending (upo-income-budget dataset)
upodata <- openspending.aggregate("upo-income-budget",drilldown=c("articulo"))
upodata.df <- openspending.as.data.frame(upodata)
# Retrieving Universidad de Granada data at openspending (ugr-income dataset)
ugrdata <- openspending.aggregate("ugr-income",drilldown=c("articulo"))
ugrdata.df <- openspending.as.data.frame(ugrdata)
# Coercing values "tolower" for improving merging
upodata.df$articulo.label <- sapply(upodata.df$articulo.label, tolower)
ugrdata.df$articulo.label <- sapply(ugrdata.df$articulo.label, tolower)
# Merge by "articulo" column
articulo.df <- merge(upodata.df, ugrdata.df, by.x="articulo.label", by.y="articulo.label", all=TRUE)
articulo.sub <- subset(articulo.df, select = c("articulo.label", "amount.x", "amount.y"))
names(articulo.sub) <- c("Articulo", "UPO", "UGR")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment