I created a spatial polygon file from a classified gridded dataset using the grid2polygons function in R. I would now like to take that polygon file and merge any polygons containing less than 6 pixels with its nearest largest neighbor. In the image link below, you can see an example of small polygons circled in blue. I would like those merged with the larger surround polygon. Alternatively, if there is a way to create a minimum threshold of 6 clumped pixels prior to the conversion to polygon stage, any suggestions for that method would be great as well.
There is a function in Gdal: gdal_sieve.py that can do exactly this (http://www.gdal.org/gdal_sieve.html) if you would like to get an idea of exactly what I would like to do. Does anyone know of a way to do this in R?