title: How do I combine a dataframe with a spatial dataframe when receiving errors with both left_join and merge?
body: <p>I am attempting to merge a dataframe containing data on hospital visits ("Hospital_Visits_df") with a shapefile/spatial*dataframe containing ZIP/ZCTA polygons and coordinates ("shp", downloaded from the <a href="https://catalog.data.gov/dataset/tiger-line-shapefile-2018-2010-nation-u-s-2010-census-5-digit-zip-code-tabulation-area-zcta5-na" rel="nofollow noreferrer">Census Bureau</a>). </p>
  
  <p>Both dataframes contain a matching column, <code>ZCTA</code> and <code>GEOID10</code>, respectively, though <code>shp</code> contains polygons for the entirety of the USA, which I will pare down to the relevant states later.</p>
  
  <p>I have attempted using both <code>merge()</code> and <code>left_join()</code>, but both results in their own errors. </p>
  
  <p><code>shp_hospital_zip1 &lt;- merge(shp, Hospital_Visits_df, by.x = "GEOID10", by.y = "ZCTA")</code></p>
  
  <blockquote>
    <p>Error in .local(x, y, ...) : non-unique matches detected</p>
  </blockquote>
  
  <p>But there are no duplicates in either column.</p>
  
  <pre><code>shp_hospital_zip2 &lt;- shp@data %&gt;% 
     left_join(Hospital_Visits_df, by = c("GEOID10" = "ZCTA"))
  </code></pre>
  
  <p>which appeared to work, except when I went to <code>summary(shp_hospital_zip2)</code> it no longer specifies it as a spatial data frame. </p>
  
  <p>I am looking to merge my hospital visit data with the spatial data so that I can plot it with leaflet, but I am getting tripped up at the first step.</p>
  
  <p>I appreciate any help you can give me. Thank you very much !!</p>