[R-sig-Geo] Combing attribute table with polygon??

Zia Ahmed zua3 at cornell.edu
Wed Jan 27 22:58:34 CET 2010


I have created one data table and one polygon in R. Both have a similar 
type of column.  I want to combine or join them with this column or 
field ("MUKEY").  Then  I will convert this polygon  as  a ESRI  shape 
file.
But  when  I  used  spCbind,   I got error. I think i miss something here.
Is there any way join attribute table with polygon? Thanks
Zia

poly.data1 <- spCbind(poly.data, data.table)
 Error in spCbind(poly.data, data.table) : different numbers of rows


names(poly.data) # polygoan
[1] "AREASYMBOL" "SPATIALVER" "MUSYM"      "MUKEY"    
 > names(data.table) # data
 [1] "MUKEY" "Sand"  "Silt"  "Clay"  "pH"    "CEC"   "EC"    "SAR"   "CaCO3"
[10] "SOM"   "BD"    "AWC"   "KSAT"  "Kf"    "Kw"    "LL"    "LEP" 

 > length(poly.data$MUKEY)
[1] 76969
 > length(data.table$MUKEY)
[1] 184
 >


poly.data1 <- spCbind(poly.data, data.table)

combinedShp1 <- "D:/test/combined1.shp" 
writeOGR(poly.data1, dsn=combinedShp1, layer="combined1", driver="ESRI 
Shapefile")



More information about the R-sig-Geo mailing list