• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Merging Dataset in R returns unexpected NA values

Resolved: Merging Dataset in R returns unexpected NA values

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

For this week tidytuesday 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 purpose
As can be seen from the code, after doing some data wrangling with the FIPS codes, I tried to merge this data with the US counties’ geospatial data by using left_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!

data-wrangling merging-data r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to separate multiple answers in one column, for multiple columns, by creating extra columns

26/03/2023

Resolved: How to set consistent decimal separators in R data frame?

26/03/2023

Resolved: How to resolve LNK2001 in c++ projects

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.