Open aappling-usgs opened 6 years ago
Within dataRetrieval
there's some data frames included that have state and county information:
library(dataRetrieval)
names(stateCd)
[1] "STATE" "STUSAB" "STATE_NAME" "STATENS"
names(countyCd)
[1] "STUSAB" "STATE" "COUNTY" "COUNTY_NAME"
[5] "COUNTY_ID"
So, if you were looking up things by states for instance, you could:
for(st in stateCd$STATE){
there are also 2 helper functions stateCdLookup
and countyCdLookup
. The 2 arguments are basically input and desired output:
fullName <- stateCdLookup("wi", "fullName")
fullName
[1] "Wisconsin"
abbriev <- stateCdLookup("Wisconsin", "postal")
abbriev
[1] "WI"
id <- stateCdLookup("WI", "id")
id
[1] 55
name <- countyCdLookup(state = "OH", county = 13, output = "fullName")
name
[1] "Belmont County"
I think @ldecicco-USGS pointed out that the current code for getting state codes could be simplified by using the right dataRetrieval function.
Here's what we currently have in wqp_inventory.R that could probably be simplified: