What can cause a “unique match” error in r merging?

I am trying to combine a spatial polygon data frame with a data frame, but I keep getting the "unique match matches" error. I ran duplicated () on the columns used for .x and by.y and no duplicates were found. 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

Call

duplicated(Africa.sh$NAME)
duplicated(AnteNatal.df$Country)

both return lists containing all FALSE. However, when I try to unite, I get

> merge(Africa.sh,AnteNatal.df, by.x = "NAME", by.y ="Country")
Error in .local(x, y, ...) : non-unique matches detected
+4
source share
1 answer

Use the sp :: merge function with the duplicateGeoms argument set to TRUE (if TRUE geometries in x are duplicated, if there are several matches between entries in x and y)

    require(sp)
    ?sp::merge
    merge(spatial_data, data_frame, by = 'match_column', duplicateGeoms = TRUE)

( , , , )

+8

All Articles