I have a line of code that renames the id's of polygons in a SpatialPolygonsDataFrame
by directly manipulating the ID
slot of the polygon. I'm a bit slow when it comes to sapply
, having used for
loops for at least 20 years. Anyhow I have a piece of code that works using a for
loop, but its really slow. I would like to replace it with a sapply
command but can't figure it out. My code looks like this:
for(v in 1:nrow(SPoly)) {
SPoly@polygons[[v]]@ID <- SPoly@data[v,3]
}
Can anyone suggest an sapply
implementation of same?