[R-sig-Geo] Ordering shapefile

Jason Gasper Jason.Gasper at noaa.gov
Sat Sep 27 00:31:11 CEST 2008


I am using the readShapePoly() function in the maptools package to read 
in shape files.  I need to order an attribute in the shapefile in 
ascending order. For example, I have three attributes: C1,C2,C3
             C1         C2         C3
[1,] -0.5658135  0.0374106 -1.7702093
[2,]  0.6783104 -0.1110221 -0.7005937
[3,] -0.2228110  0.9176706  1.7612472

ordered attributes based on ascending order in C2 would look like this:

             C1         C2         C3
[1,]  0.6783104 -0.1110221 -0.7005937
[2,] -0.5658135  0.0374106 -1.7702093
[3,] -0.2228110  0.9176706  1.7612472

The problem of course is that I am dealing with a shapefile and thus 
cannot treat the attributes as a vector using the "order" function.  Has 
anyone found a way to order attributes in a shapefile? The reason I need 
to do this is that I have a bunch of 0's that I will need to eliminate 
after spatial weights are created (using the poly2nb() and nb2WB() 
functions.  So I need the index for spatial weighting and cannot simply 
pull out each attribute and create a new sorted vector.




More information about the R-sig-Geo mailing list