I am trying to merge a spatial polygons data frame and a data frame, but I keep getting a “non-unique matches detected” error. I have run duplicated() on the columns used for by.x and by.y and no duplicates are detected. What else could cause this error?
> head(AnteNatal.df)
              Country Year(s) AnteNatalValue
1         Afghanistan    2011           14.6
2             Albania    2009           66.8
3              Angola    2009           47.1
4 Antigua and Barbuda    2011          100.0
5           Argentina    2006           24.7
6             Armenia    2010           92.8
> Africa.sh$NAME[1:5]
[1] Angola       Burundi      Benin        Burkina Faso Botswana    
243 Levels: Afghanistan Aland Albania Algeria American Samoa Andorra Angola        Anguilla Antarctica ... Zimbabwe
The calls
duplicated(Africa.sh$NAME)
duplicated(AnteNatal.df$Country)
both return lists containing all FALSE. However, when I try to merge, I get
> merge(Africa.sh,AnteNatal.df, by.x = "NAME", by.y ="Country")
Error in .local(x, y, ...) : non-unique matches detected
Use the sp::merge function with the duplicateGeoms argument set to TRUE (if TRUE geometries in x are duplicated if there are multiple matches between records in x and y)
    require(sp)
    ?sp::merge
    merge(spatial_data, data_frame, by = 'match_column', duplicateGeoms = TRUE)
(I know this question is older, but I came across it while in search for an answer to it myself)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With