IndiaPIN: R Data Package

Posted on Jan 11, 2022

IndiaPIN contains geographic details about 19,300 PIN codes in India. Some PIN codes had more than one offices. Only the first office of that PIN code area has been retained in those cases. (Updated: December 2021.)

Variables

  1. Circle: (chr) Name of the Postal Circle
  2. Region: (chr) Name of the Postal Region
  3. Division: (chr) Name of the Postal Division
  4. Office: (chr) Name of Postal Office
  5. PIN: (int) Six-digit PIN Code
  6. District: (chr) Name of the District
  7. State: (chr) Name of the State
  8. Latitude: (dbl) Latitude
  9. Longitude: (dbl) Longitude

Data Source

Department of Posts, Ministry of Communications, Government of India. URL: https://www.indiapost.gov.in/vas/pages/findpincode.aspx. Wrangled for this package by Harshvardhan (https://harsh17.in/).


Installation

# install `devtools` if not already installed
if (!require("IndiaPIN")) 
    devtools::install_github("harshvardhaniimi/IndiaPIN")
## Loading required package: IndiaPIN
# Tidyverse
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# load IndiaPIN
library(IndiaPIN)
data(IndiaPIN)

Example

Data and Variables

IndiaPIN
## # A tibble: 18,169 × 9
## # Groups:   PIN [18,169]
##    Circle        Region Division Office    PIN District State Latitude Longitude
##    <chr>         <chr>  <chr>    <chr>   <int> <chr>    <chr>    <dbl>     <dbl>
##  1 Andhra Prade… Kurno… Hindupu… Pedda… 515631 ANANTAP… ANDH…     14.6      77.9
##  2 Andhra Prade… Kurno… Hindupu… Obula… 515581 ANANTAP… ANDH…     14.2      78.3
##  3 Andhra Prade… Kurno… Hindupu… Gurra… 515571 ANANTAP… ANDH…     13.9      78.2
##  4 Andhra Prade… Kurno… Hindupu… Halli… 515311 ANANTAP… ANDH…     13.8      77.0
##  5 Andhra Prade… Kurno… Hindupu… Tamma… 515281 ANANTAP… ANDH…     14.1      77.0
##  6 Andhra Prade… Kurno… Hindupu… Bussa… 515241 ANANTAP… ANDH…     14.0      77.7
##  7 Andhra Prade… Vijay… Tadepal… Kavul… 534176 WEST GO… ANDH…     16.6      80.6
##  8 Bihar Circle  East … Bhagalp… Kathr… 813105 BANKA    BIHAR     84.5      24.2
##  9 Bihar Circle  East … Bhagalp… Kasri… 813203 BHAGALP… BIHAR     87.3      25.3
## 10 Bihar Circle  East … Bhagalp… Akida… 853202 BHAGALP… BIHAR     25.4      84.3
## # ℹ 18,159 more rows

Number of PIN codes by State/UT

IndiaPIN %>% 
  group_by(State) %>% 
  summarise(Count = n()) %>% 
  arrange(desc(Count)) %>% 
  print(n = 40)
## # A tibble: 35 × 2
##    State                                        Count
##    <chr>                                        <int>
##  1 TAMIL NADU                                    2032
##  2 UTTAR PRADESH                                 1581
##  3 MAHARASHTRA                                   1466
##  4 KERALA                                        1425
##  5 KARNATAKA                                     1188
##  6 WEST BENGAL                                   1125
##  7 ANDHRA PRADESH                                1071
##  8 GUJARAT                                       1007
##  9 RAJASTHAN                                      986
## 10 ODISHA                                         933
## 11 BIHAR                                          853
## 12 MADHYA PRADESH                                 760
## 13 ASSAM                                          571
## 14 PUNJAB                                         531
## 15 TELANGANA                                      482
## 16 HIMACHAL PRADESH                               436
## 17 JHARKHAND                                      360
## 18 HARYANA                                        310
## 19 UTTARAKHAND                                    300
## 20 CHHATTISGARH                                   240
## 21 JAMMU AND KASHMIR                              195
## 22 DELHI                                           97
## 23 GOA                                             88
## 24 CHANDIGARH                                      25
## 25 PUDUCHERRY                                      22
## 26 SIKKIM                                          19
## 27 MEGHALAYA                                       16
## 28 TRIPURA                                         10
## 29 MIZORAM                                          9
## 30 THE DADRA AND NAGAR HAVELI AND DAMAN AND DIU     8
## 31 LAKSHADWEEP                                      7
## 32 ARUNACHAL PRADESH                                5
## 33 NAGALAND                                         5
## 34 ANDAMAN AND NICOBAR ISLANDS                      4
## 35 LADAKH                                           2

PIN Code Locations on Map

I will use leaflet package to plot randomly selected 50 PIN codes. I am adding the Region and Circle name in the popup.

library(leaflet)
library(tidyverse)
library(IndiaPIN)

data("IndiaPIN")

set.seed(4)
index = sample(nrow(IndiaPIN), 50)
data = IndiaPIN::IndiaPIN[index,]

l1 = data$Longitude
l2 = data$Latitude
pop = paste(data$Region, data$Circle, sep = ", ")

m = leaflet() %>% 
   addTiles() %>% 
   addMarkers(lng=l1, lat=l2, popup = pop)

m

Also see this Stackoverflow thread to understand how to save the plots.

See Github for source code.