Transform local to zip code

Does anyone know a script in R, or could you help me put together one, which takes the name of a location and fetches the ZIP code of this one?

Author: Leonel Sanches da Silva, 2014-08-26

2 answers

Google provides the ZIP code in some cases and there are already packages with functions to access the Google API, the ggmap he's one of them.

For example:

library(ggmap)
end <- geocode("Avenida das Americas, 4666 - Barra da Tijuca, Rio de Janeiro", output="more")
end$postal_code
[1] "22640-102"

However you have to keep in mind that this uses Google Maps, which is quite sensitive to the way you query and will not necessarily have everything you want to search.

 6
Author: Carlos Cinelli, 2014-08-26 15:51:07

An alternative to Carlos ' answer is to load a CEPs base (acquired) and search directly on it.

I used the sample CSV file from the Site QualOCep (I don't know the site, and I think it should ideally be more guaranteed to buy this data directly from the Post Office )

> cep_data = read.table('cepbr_texto_exemplo.csv', header=TRUE, sep=';')
> query = subset(cep_data, Logradouro=="Max William Silva Gomes")
> cep = query[1]
> query
  CEP Tipo_Logradouro              Logradouro Complemento Local
  1 8382342             Rua Max William Silva Gomes                  
  Bairro     Cidade UF     Estado
  1 Recanto Verde do Sol São Paulo SP São Paulo
> cep
  1 8382342
 3
Author: Luiz Vieira, 2014-08-26 16:03:10