Skip to content
Prev 12491 / 29559 Next

Merging a list of SpatialPointsDataFrame objects

I used a mapply() statement to create a list of SpatialPointsDataFrame
objects -- each of the list entries is a SpatialPointsDataFrame
object, and each SpatialPointsDataFrame object has the identical @data
*names* (e.g. the dataframe is rbindable for all of the objects).
What I'm wondering is if there is an efficient way to merge all of
these into a single SpatialPointsDataFrame object -- I can (I suppose)
do an rbind or spRbind, but it seems like I'd have to loop through the
list entry one at a time, appending each successive
SpatialPointsDataFrame object into the growing "mega"
SpatialPointsDataFrame.  Is there a cleaner/faster way to do this in
R?  Thanks!

Here's an example using the built in data/examples:

require(sp)
data(meuse) # reload data.frame
coordinates(meuse) = c("x", "y") # specify column names

meuse1=meuse[1:10,]
meuse2=meuse[11:20,]
meuse3=meuse[21:50,]
meuse_list=list(meuse1,meuse2,meuse3)

# Brute Force way:
for(i in 1:length(meuse_list))
{
	if(i==1)
	{
		meuse_merged=meuse_list[[i]]
	} else
	{
		meuse_merged=rbind(meuse_merged,meuse_list[[i]])
	}	
}



--j