I have a ESRI shapefile with which I do further work in R. It contains polygons of administrative units and their keys. Key value of one unit is incorrect and I need to rewrite it to be able to join my data later on (it is not practical to change the key value in my data).
Changing the key value in the
sp object directly gives me an error:
srcShape[srcShape$KOD_ORP == "1000", ]$KOD_ORP <- "3018" Error in as.vector(data) : no method for coercing this S4 class to a vector
I am able to sidestep the error by first taking the entire data slot out of the
sp object, changing it as data frame, and pasting it back in.
asdf <- srcShape@data asdf[asdf$KOD_ORP == "1000", ]$KOD_ORP <- "3018" srcShape@data <- asdf
I am however not comfortable rewriting the data slot in such a blunt way; it contains hundreds of polygons and I am afraid of messing up the polygon / key relationship.
Is there a safer solution for this? And is the behavior I see a bug, or a feature of Spatial DataFrame objects and exists there for a reason?