Join a shapefile with a data.frame with missing data in data.frame using R.

I'm trying to join a data frame with a shapefile using R. My shapefile has 7 features, corresponding to 7 regions of my city.
My data.frame has reptile data in 6 regions of my city, but in one region no reptiles were found.

I'm using the sp::merge command to join the shapefile and data.frame, but when I do the union, the region that doesn't have a reptile doesn't appear.

#load data.frame

#calc data
#Total de Serpente

#load shapefile

#join shp and data.frame
total_especies_shp<-sp::merge(regiao, total_especies, by="regiao_cg")

output file

Since you are using {sf} anyhow, and sf package objects are modified data frames you can consider dplyr::left_join() to merge the two data frames.

Just be sure to start the pipe from your shapefile, as the output of a join inherits from the first object (and you want to end up with a sf object as output.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.