IndiaPIN: R Data Package
R Package for All India PIN Codes Directory with Latitude and Longitude Details (Updated: December 2021)
January 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.)
Wrote my first public R package today. Indian PIN codes directory with Latitude and longitude details. ✨
— Harshvardhan (@harshbutjust) January 2, 2022
Took much shorter than I expected (less than six hours). Still need to work on vignettes and online documentation though. https://t.co/wZ0p6Kle6B
Variables
- Circle: (chr) Name of the Postal Circle
- Region: (chr) Name of the Postal Region
- Division: (chr) Name of the Postal Division
- Office: (chr) Name of Postal Office
- PIN: (int) Six-digit PIN Code
- District: (chr) Name of the District
- State: (chr) Name of the State
- Latitude: (dbl) Latitude
- 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 packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.8.9000
## ✓ tidyr 1.2.0 ✓ stringr 1.4.0
## ✓ readr 2.1.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
# 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
## # … with 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.