Question:
For this weektidytuesday
challenge, I was trying to inspect the drought data. I wanted to make a spatial map to see the US counties’ drought level. To this end, I tried to merge geospatial data from maps
package with the existing data. Here is my code for that purposeleft_join
function. The resulting counties
data includes several NA values for state, state_code, county_code
columns, which I really do not understand why this happens. Therefore, I would be glad if you can advise me on why I am receiving these NA values. Thank you for your attention.Answer:
Printing out the table in a tibble you can see that the county data has a space between within the quotations:head(tibble(fips_codes))
Using
fips_codes$county <- str_trim(fips_codes$county)
Solves the issue. Now it should work fine. I’ts not necessary to add another line of code though you can change your gsub with:
fips_codes$county <- gsub(".County", "", as.character(fips_codes$county))
If you have better answer, please add a comment about this, thank you!