[R-sig-Geo] ordering of data in polygons shapefile

Roger Bivand Roger.Bivand at nhh.no
Wed Jan 19 11:12:24 CET 2011

On Wed, 19 Jan 2011, Franziska Schulze wrote:

> Hallo,
> I still have another question:
> I have a polygon shapefile and I want to use it in order to construct my 
> neighbors object and listw object to perform spatial econometric tests and to 
> estimate a spatial model. The problem ist that the regions in my shapefile 
> are not ordered as they should be in order to match with the other variables. 
> Therefore, my question is whether it is possible to order a spatial polygons 
> data frame with respect to one of its attributes. (The attribute is a region 
> id number which has to ordered in increasing order.)

Yes, it is possible, but it is better practice and much easier to reorder 
the other data, and add it with spCbind() in maptools to the 
SpatialPolygonsDataFrame object. You need to make sure that the match 
between the row.names() of the SpatialPolygonsDataFrame object and the 
row.names() of the additional data stored as a data.frame object is exact. 
Look at the example for ?spCbind for further details. Re-ordering a 
data.frame object is a standard operation in R.

Hope this helps,


> Thanks in advance!
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> 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