Skip to content

Instantly share code, notes, and snippets.

@fontanon
Last active December 21, 2015 17:29

Revisions

  1. fontanon renamed this gist Aug 26, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. fontanon revised this gist Aug 26, 2013. 1 changed file with 37 additions and 1 deletion.
    38 changes: 37 additions & 1 deletion openspending-merge-test
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,40 @@ 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")
    names(articulo.sub) <- c("Articulo", "UPO", "UGR")

    # Result
    # Articulo UPO UGR
    # 1 de comunidades autónomas 55556053 30465000
    # 2 de comunidades autónomas 55556053 259498608
    # 3 de corporaciones locales 604585 90000
    # 4 de corporaciones locales 604585 30000
    # 5 de empresas privadas 1944825 1400000
    # 6 de empresas privadas 1944825 1275000
    # 7 de empresas públicas y otros entes públicos NA 400000
    # 8 de familias e instituciones sin fines de lucro NA 200000
    # 9 de familias e i.s.f.l. 50000 NA
    # 10 de la administracion del estado 5729768 NA
    # 11 de la administración general del estado NA 10600000
    # 12 de la administración general del estado NA 22245000
    # 13 de la junta de andalucia 239292345 NA
    # 14 de la seguridad social NA 3000000
    # 15 del exterior NA 4000000
    # 16 del exterior NA 3500000
    # 17 de organismos autónomos administrativos NA 70000
    # 18 de organismos autónomos administrativos NA 693000
    # 19 ingresos por prestación de servicios NA 8850000
    # 20 intereses de depositos 748397 NA
    # 21 intereses de depósitos NA 500000
    # 22 otros ingresos 3685574 75000
    # 23 otros ingresos patrimoniales NA 406000
    # 24 otros ingresos procedentes prestaciones servicios 8621000 NA
    # 25 precios públicos 46393636 44740000
    # 26 prestamos recibidos 4334926 NA
    # 27 productos de concesiones y aprov. especiales 844072 NA
    # 28 reintegro de préstamos concedidos NA 650000
    # 29 reintegros de operaciones corrientes 116797 NA
    # 30 reintegros de préstamos concedidos 300000 NA
    # 31 rentas de bienes inmuebles 133837 600000
    # 32 tasas 1991510 1900000
    # 33 venta de bienes 87658 250000
  3. fontanon revised this gist Aug 26, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion openspending-merge-test
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ upodata.df <- openspending.as.data.frame(upodata)
    ugrdata <- openspending.aggregate("ugr-income",drilldown=c("articulo"))
    ugrdata.df <- openspending.as.data.frame(ugrdata)

    # Coerce values tolower to improve matching
    # 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)

  4. fontanon revised this gist Aug 26, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion openspending-merge-test
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ library("ropenspending")
    upodata <- openspending.aggregate("upo-income-budget",drilldown=c("articulo"))
    upodata.df <- openspending.as.data.frame(upodata)

    # Retrieving Universidad de Granada data at openspending (upo-income-budget dataset)
    # 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)

  5. fontanon created this gist Aug 26, 2013.
    18 changes: 18 additions & 0 deletions openspending-merge-test
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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 (upo-income-budget dataset)
    ugrdata <- openspending.aggregate("ugr-income",drilldown=c("articulo"))
    ugrdata.df <- openspending.as.data.frame(ugrdata)

    # Coerce values tolower to improve matching
    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")