[R-sig-Geo] add, delete columns in spatial data frame data slot before spRbind

Roger Bivand Roger.Bivand at nhh.no
Tue Aug 19 22:00:29 CEST 2008


On Tue, 19 Aug 2008, Murray Richardson wrote:

> Hello again users,
>
> I'm having trouble figuring out how to format the data slot in spatial 
> SpatialPolygonsDataFrames.  I need to use spRbind to combine polygons from 
> different shapefiles but encounter the problem of having different numbers of 
> columns, and also non-unique IDs.  If the polygons come from different 
> shapefile sources and have different columns in the dbf, what is the best way 
> to format them to use spRbind?
>
> Can't seem to find some info on this.

See rbind for data frames - it cannot be done by design. The columns of 
the data frames to be stacked must have the same names and types of data 
for the same names. If they differ, you'll have to create a combined data 
frame with NAs and copy across. In addition, you must have unique IDs, so 
perhaps start there, insert the relevant IDs into the combined data frame, 
and rebuild the whole object. Probably you should drop as many columns 
from your input data as possible to reduce the work to be done.

Roger

>
> Thanks for any help.
>
> Murray
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list