[R-sig-Geo] Merging a list of SpatialPointsDataFrame objects
Jonathan Greenberg
greenberg at ucdavis.edu
Thu Aug 11 05:39:54 CEST 2011
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
--
Jonathan A. Greenberg, PhD
Assistant Project Scientist
Center for Spatial Technologies and Remote Sensing (CSTARS)
Department of Land, Air and Water Resources
University of California, Davis
One Shields Avenue
Davis, CA 95616
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307
More information about the R-sig-Geo
mailing list