get FIPS for a county based on part of the countyname and state abbrev
Source:R/FIPS_FUNCTIONS.R
fips_counties_from_countyname.Rd
get FIPS for a county based on part of the countyname and state abbrev
Arguments
- countyname_start
first few letters of countyname to look for via grep("^x", ) like "Johnson" or "Johnson County". Ignores case.
- ST
two letter abbreviation of State, such as "TX" – Can only be omitted if the 1st parameter has the full name and ST like "Harris County, TX". Ignores case.
- exact
TRUE requireS exact matches, FALSE to allow partial matches which here means first few letters match (it is not using grep), and in which case outputs might differ from inputs in length and not be 1-to-1
Value
the county FIPS (5 digits long with leading zero if needed, as character) but can return more than one guess per input name!
Examples
fips2name(fips_counties_from_countyname("Har", "TX")) # finds 5 matches
#> Warning: NA returned for 1 values that failed to match
#> [1] NA
fips_counties_from_countyname("Har", "TX") # finds 5 matches
#> [1] NA
fips_counties_from_countyname("Harris", "TX") # finds 2 matches
#> [1] NA
fips_counties_from_countyname("Harris ", "TX") # finds 1 match
#> [1] NA
fips_counties_from_countyname("Harris County", "TX") # same
#> [1] "48201"
fips_counties_from_countyname("harris county, tx", "TX") # same
#> [1] NA
fips_counties_from_countyname("Harris County, Texas", "TX") # finds 0 if state spelled out
#> [1] NA
fips_counties_from_countyname("harris county, tx") # can omit ST param like this
#> [1] "48201"
fips_counties_from_countyname("Harris County TX") # needs comma
#> [1] NA