FIPS - Add leading zeroes to fips codes if missing, replace with NA if length invalid
Source:R/FIPS_FUNCTIONS.R
fips_lead_zero.Rd
Ensures FIPS has the leading zero, but does NOT VALIDATE FIPS - It does NOT check if FIPS is valid other than checking its length. fips could be a state, county, tract, blockgroup, or block FIPS code.
Examples
testfips1 <- c(1,"01",1234,"1234","12345",123456)
testfips <- c(1, "1", "12", "123", "1234", "12345", "", NA, "words")
fips_lead_zero(testfips1)
#> [1] "01" "01" "01234" "01234" "12345" "0123456"
fips_lead_zero(testfips)
#> Warning: 4 fips had invalid number of characters (digits) or were NA values
#> [1] "01" "01" "12" NA "01234" "12345" NA NA NA