Giter VIP home page Giter VIP logo

brazilpopulation's Introduction

Brazil's Population

Creating a dataset about the Brazil's population from the last 20 yeas (1998 - 2017)
author: Rodrigo Silva

knitr::opts_chunk$set(echo = FALSE)

The goal of this project is just create a dataset about Brazil's population from the last 20 years to make easy any demographic processing. All the data was obtained from IBGE (Brazilian Institute of Geography and Statistics) and TCU (Federal General Accounting Office).

library(foreign)
library(dplyr)
setwd('Data/')

files <- list.files(pattern = '.DBF')

myfiles <- lapply(files, read.dbf)

populacao <- do.call(rbind, myfiles)

Nomenclature of municipalities and regions


municipios <- read.csv2('Municipios_Brasileiros.csv', header=TRUE, sep = ',')

regioes <- read.csv2('UF-Regiões.csv', header = TRUE)

Merging data about location

names(municipios)[3] <- 'CO_UF'

brasil <- merge(municipios, regioes, all.x = TRUE)

Filtering for the desired parameters

brasil <- brasil %>%
  select(Código.IBGE, Nome.do.Município, Estado, UF, NO_REGIAO, Latitude, Longitude)

Renaming columns


# Location
names(brasil)[1] <- 'code'
names(brasil)[2] <- 'city'
names(brasil)[3] <- 'state'
names(brasil)[4] <- 'abbreviation'
names(brasil)[5] <- 'region'
names(brasil)[6] <- 'lat'
names(brasil)[7] <- 'long'

# Population
names(populacao)[1] <- 'code'
names(populacao)[2] <- 'year'
names(populacao)[3] <- 'population'

The code about municipalities used to have 7 digits, the 7th digit was necessary to verify the code, so as we don't use it anymore I'll cut it out from the data.

brasil$code <- substr(as.character(brasil$code),1,6)

Other thing is bothering me is the name REGIAO in the region column, I gonna take it out too.

brasil$region <- substr(as.character(brasil$region), 8, 20)

Merging data about population with data about location

resultado <- merge(brasil, populacao, all.x = TRUE)

Spreading the result to better viewing


library(tidyr)

resultado_horizontal <- spread(resultado, year, population)

Exporting results

write.csv2(resultado, "brazil-population-2012-2017.csv", row.names = FALSE)

write.csv2(resultado_horizontal, "brazil-population-2012-2017-spread.csv", row.names = FALSE)

ASAP I'll continue improving this dataset! I really hope you enjoy this!

brazilpopulation's People

Contributors

rdsilva avatar

Stargazers

Jean Prado avatar Gabriel Santos avatar Nitai Bezerra  avatar Matheus Almeida avatar  avatar Gabriel Aparecido Fonseca avatar Alberto Segundo avatar

Watchers

James Cloos avatar Jaqueline Fernandes avatar  avatar

brazilpopulation's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.