I am trying to merge a dataframe to an sf object, but having difficulties as the sf objects has a multipolygon vector column holding its co-ordinates and the dataframe has two different columns (x anf y) for its co-ordinates.
I have tried two different methods so far.
new_spat <- merge(sf,df, by.x="vector", by.y=c("x","y"),sort=FALSE)
this came up with an error that the by.x and by.y are specifying two different lengths of columns.
I also tried converting the data frame to a spatial points data frame by converting x and y to coordinates and then merging on the coords column that was created.
new_spat <- merge(sf,df_spatial, by.x="vector", by.y="coords",sort=FALSE)
this instead came up with an error saying by.y must specify a uniquely named column.
Any help would be appreciated.