Description Usage Arguments Details Value Note Examples
For events reported by forecast zone, use regular expressions to match as many as possible to counties.
1 | match_forecast_county(storm_data_z)
|
storm_data_z |
A dataframe of storm events reported by forecast zone
(i.e.,
|
This function tries to match the cz_name
of each event to
a state and county name from the county.fips
dataframe that comes
with the maps
package. The following steps are taken to try to
match each cz_name
to a state and county name from county.fips
:
Tries to match cz_name
to the county name in county.fips
after removing any periods or apostrophes in cz_name
.
Next, for county names with "county" in them, try to match the word before
"county" to county name in county.fips
. Then check the two words before
"county", then the one and two words before "counties".
Next, pull out the last word in cz_name
and try to match it to the county
name in county.fips
. The check the last two words in cz_name
, then check
the last three words in cz_name
.
Next, pull any words right before a slash and check that against the county name.
Finally, try removing anything in parentheses in cz_name
before matching.
The dataframe of events input to the function, with county FIPS
added for events matched to a county in the fips
column. Events
that could not be matched are kept in the dataframe, but the fips
code is set to NA
.
This function does not provide any matches for events outside of the continental U.S.
You may want to hand-check that event listings with names like "Lake", "Mountain", and
"Park" have not been unintentionally linked to a county like "Lake County". While such
examples seem rare in the example data used to develop this function (NOAA Storm Events
for 2015), it can sometimes happen. To do so, you can use the str_detect
function
from the stringr
package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | counties_to_parse <- dplyr::data_frame(
event_id = c(1:19),
cz_name = c("Suffolk",
"Eastern Greenbrier",
"Ventura County Mountains",
"Central And Southeast Montgomery",
"Western Cape May",
"San Diego County Coastal Areas",
"Blount/Smoky Mountains",
"St. Mary's",
"Central & Eastern Lake County",
"Mountains Southwest Shasta County To Northern Lake County",
"Kings (Brooklyn)",
"Lower Bucks",
"Central St. Louis",
"Curry County Coast",
"Lincoln County Except The Sheep Range",
"Shasta Lake/North Shasta County",
"Coastal Palm Beach County",
"Larimer & Boulder Counties Between 6000 & 9000 Feet",
"Yellowstone National Park"),
state = c("Virginia",
"West Virginia",
"California",
"Maryland",
"New Jersey",
"California",
"Tennessee",
"Maryland",
"Oregon",
"California",
"New York",
"Pennsylvania",
"Minnesota",
"Oregon",
"Nevada",
"California",
"Florida",
"Colorado",
"Wyoming"))
match_forecast_county(counties_to_parse)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.