[R-sig-Geo] Combing attribute table with polygon??
Zia Ahmed
zua3 at cornell.edu
Thu Jan 28 03:29:33 CET 2010
Thank you so much Roberts! it works.
Zia
Robert J. Hijmans wrote:
> Zia, something like this might work as long as MUKEY has no NA values:
>
> poly.data = merge(poly.data, data.table, by="MUKEY" ,all.x = TRUE)
>
> Robert
>
> On Wed, Jan 27, 2010 at 1:58 PM, Zia Ahmed <zua3 at cornell.edu> wrote:
>
>> 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")
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
More information about the R-sig-Geo
mailing list