[R-sig-Geo] question on adding variable to .dbf file

Stephen Sefick sas0025 at auburn.edu
Mon Oct 8 16:40:14 CEST 2012


Look at the foreign package

?read.dbf

On Mon 08 Oct 2012 09:07:33 AM CDT, Zijdeman, R.L. (Richard) wrote:
> Dear all,
>
> I am trying to add and then display regional characteristics (e.g. population size) to an existing map. The map comes as a .shp file, including .sbn, .sbx, .shx and .dbf file and portrays municipality borders.  However, once I have added a new column to the .dbf file, I am unable to reread the .shp file and get the following error:
> Error in `row.names<-.data.frame`(`*tmp*`, value = value) :   invalid 'row.names' length.
>
> Here's what I do:
>
> # To read the map:
> munis<-readShapePoly("nl_1890.shp")
>
> # To merge the new column with the original data:
> munis2<-merge(munis,y, by.x="acode", by.y="hplts_adam_code", all.x)
> # acode is key in the original file, to be merged with "hplts_adam_code" from the file containing regional information
>
> head(munis2,3)
> # acode GM_1890      GM_NAAM cbscode   famprop
> # 1 10002    0136    Zuidlaren     136 1.0000000
> # 2 10005    0086   Opsterland      86 1.0000000
> # 3 10007    0981        Vaals     981 0.1250000
>
> # Since I thought it was important, I changed the order of the variables back to the original order, with the added column "famprop" as last one:
> munis2<- munis2[c(2,3,4,1,5)]
> # GM_1890    GM_NAAM cbscode acode famprop
> # 1    0136  Zuidlaren     136 10002   1.000
> # 2    0086 Opsterland      86 10005   1.000
> # 3    0981      Vaals     981 10007   0.125
>
> # next I write munis2 into the .dbf file (using the original name for the .dbf file)
> write.dbf(munis2,"nl_1890")
>
> # finally I try to read in the .shp file again
> munis2shp<-readShapePoly("nl_1890.shp")
>
> # but this result in the following error:
> Error in `row.names<-.data.frame`(`*tmp*`, value = value) :
>   invalid 'row.names' length
>
> I am quite novice to R and mapping data, so any advice on either code or my approach is very much appreciated.
>
> Best,
>
> Richard
>
>
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Stephen Sefick
**************************************************
Auburn University                                         
Biological Sciences                                      
331 Funchess Hall                                       
Auburn, Alabama                                        
36849                                                           
**************************************************
sas0025 at auburn.edu                                  
http://www.auburn.edu/~sas0025                 
**************************************************

Let's not spend our time and resources thinking about things that are 
so little or so large that all they really do for us is puff us up and 
make us feel like gods.  We are mammals, and have not exhausted the 
annoying little problems of being mammals.

                                -K. Mullis

"A big computer, a complex algorithm and a long time does not equal 
science."

                              -Robert Gentleman



More information about the R-sig-Geo mailing list