3

I am new in R and I am facing a problem. I have a list with many SpatialPolygonsDataFrames. Some of them are like this example

enter image description here

This is a SpatialPolygonsDataFrame. My "problem" is that the data.frame has two rows for this SpatialPolygonsDataFrame. How can I keep the two polygons with only one row in data.frame? I think is something like merge but how can I do this in R?

I use the sp package for geometry representation.

2
  • This is how the sp package stores multipart polygons (on separate rows). why do you want to merge the rows!? Commented Nov 19, 2015 at 11:43
  • Because I want them to have the same length (the data.frames). I will add rows and store data like area and perimeter so I want every data.frame of SpatialPolygonsDataFrames to have the same length. Is it wrong to do that? Thank you for edit.
    – g.f.l
    Commented Nov 19, 2015 at 11:49

1 Answer 1

2

You can aggregate these into a multi-polygon.

library(raster)
a <- aggregate(x, 'var')

var is the variable(s) that indicates which rows need to be grouped.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.