Skip to contents

Each state and district has a unique two and five digit code code respectively. Use this function to obtain the code for a state or district.

Usage

codes(state, district = c())

Arguments

state

The state(s) for which to obtain a code(s). Can be entered as either a state abbreviation or full name (case-insensitive).

`state` can be entered as either a single state or a vector of states. If `state` is a vector, `district` must be omitted.

district

The county for which to obtain a code. Can be entered with or without "district" (case-insensitive).

Value

The code(s) of given state or district.

If only states are entered, a vector of length equal to the number of states is returned. If any states are not found or are invalid, `NA` is returned in their place.

If a state and district are entered, a single value with the code for the given district is returned. If the district is invalid for the given state, an error is thrown.

If both `state` and `district` are omitted, the entire list of available codes are returned, sorted by the state's abbreviation.

Details

State and district codes are two and five digit codes, respectively. They uniquely identify all states and districts within India. The state and district codes is merged into one code with 5 digits. The first two digits of the five digit district codes correspond to the state that the district belongs to.

Note

A state must be included when searching for district, otherwise multiple results may be returned for duplicate district names.

See also

[code_info()]

Examples

codes()
#>  [1] "35" "37" "12" "18" "10" "22" "04" "25" "26" "30" "24" "02" "06" "01" "20"
#> [16] "29" "32" "38" "31" "27" "17" "14" "23" "15" "07" "13" "21" "03" "34" "08"
#> [31] "11" "36" "33" "16" "05" "09" "19"
codes("AP")
#> [1] "37"
codes("Tamil Nadu")
#> [1] "33"

codes(c("AP", "WB", "TN"))
#> [1] "37" "19" "33"

codes("WB", district = "Kolkata")
#> [1] "19342"
codes(state = "Uttarakhand", district = "Nainital")
#> [1] "05066"
codes(state = "RJ", district = "Pratapgarh")
#> [1] "08131"