Turn local into zip code


Does anyone know a script in the R, or could you help me put one together, that takes the name of a place and looks for the zip code of this?

asked by anonymous 26.08.2014 / 17:25

2 answers


Google provides the zip code in some cases and there are already packages with functions to access the google API, the ggmap is one of them.

For example:

end <- geocode("Avenida das Americas, 4666 - Barra da Tijuca, Rio de Janeiro", output="more")
[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 for.

26.08.2014 / 17:51

An alternative to Carlos's response is to load a base of zip codes (acquired) and search directly into it.

I used the sample CSV file from QualOCep (I do not know the site, and I think ideally you should be sure 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
26.08.2014 / 18:03