I'm trying to take a variable column and cut it up into several columns. The values follow a basic pattern with the county name having a variety of lengths and formats.
State-county :
[1] "MA: Bristol County (25005)"
[2] "LA: St. Tammany Parish (22103)"
[3] "CA: Ventura County (06111)"
[4] "CA: San Mateo County (06081)"
I need a state, county name, and county code column that I can add back into the data.frame. Been trying to figure out how to use str_extract to accomplish the task. Ideally, this is where I'd end up, but I'll take any help I can get.
state: county: county code:
[1] "MA" Bristol County 25005
[2] "LA" St. Tammany Parish 22103
[3] "CA" Ventura County 06111
[4] "CA: San Mateo County 06081
I was able to use this code I found str_extract_all( "(?<=\\().+?(?=\\))") for the county code (thanks Nettle) and the closest I could get to the state abrev was
'str_extract_all( h,"..:")
which is close but includes the ":"
also tried: str_extract_all( "(?<=\\:")
Sorry if this isn't the best format, I tried to be really clear and in the style I've seen.