Dear Tom and Roger,

Many thanks, just tried readOGR and the import was successful.

Best,
Amy


On 22 October 2013 20:05, Tom Philippi <tephilippi@gmail.com> wrote:

> Amy--
> Try using readOGR from the rgdal package.
>
> I may be wrong (I'm presently locked out of my workstation by IT support
> so I can't verify), but I'm pretty sure that spaces in rownames isn't an
> issue.
>
> I hope that this helps.
>
> Tom
>
>
> On Tue, Oct 22, 2013 at 11:56 AM, Amy Mikhail <amy.mikhail@gmail.com>wrote:
>
>> Hi,
>>
>> I am trying to create some chloropleth maps of disease incidence data for
>> the province of East Java, Indonesia.
>>
>> I can see there are a number of different packages with which I might do
>> this (e.g. the plotmap function in SpatialEpi, or maptools) but I'm having
>> difficulty importing the shapefiles.
>>
>> My problem is that all the shapefiles I can find for Indonesia very
>> frustratingly put white spaces in the names of the districts or provinces.
>>  I carefully removed the spaces in the district and province names in my
>> datafile, which means that even if the shapefile could be read into R, the
>> id names would not match - a moot point at present because I can't read in
>> the shapefiles either.
>>
>> I am using R 3.0.2 64 bit with the following packages loaded:
>>
>> library(SpatialEpi)
>> library(ggplot2)
>> library(ggmap)
>>
>> Here is the type of error I am getting:
>>
>> >Indmap <- readShapePoly(fn="IDN_adm/IDN_adm2.shp", IDvar="NAME_2")
>> Error in `row.names<-.data.frame`(`*tmp*`, value = value) :
>>   duplicate 'row.names' are not allowed
>> In addition: Warning message:
>> non-unique values when setting 'row.names': ‘Banjar’, ‘Kepulauan Riau’,
>> ‘Lampung Barat’
>>
>> *Note, at district level there are both districts and cities - some of the
>> cities have the same name as a (separate) district but they are prefaced
>> by
>> the word Kota (meaning city/town).  The above error was created because
>> there are cities and districts with the same names and there was a white
>> space between "Kota" and the city name in the shapefile.
>>
>> I'm fairly certain that some years ago I was able to remove the spaces in
>> MS excel and save the edited file as a .dbf without problems but now this
>> isn't working and I see from googling this issue that MS excel 2010 does
>> not have an option to edit and save .dbf files (they get corrupted if you
>> try).
>>
>> I then tried opening the .dbf file in MS excel, removing the white spaces,
>> saving as a .csv and re-importing into R where I was hoping write.dbf
>> would
>> work, but that gave me the following error:
>>
>> > Dmap <- read.table(file="Dmap.csv", header=TRUE, sep=",",
>> na.strings="NA")
>> > str(Dmap)
>> 'data.frame':   394 obs. of  18 variables:
>>  $ ID_0      : int  103 103 103 103 103 103 103 103 103 103 ...
>>  $ ISO       : Factor w/ 1 level "IDN": 1 1 1 1 1 1 1 1 1 1 ...
>>  $ NAME_0    : Factor w/ 1 level "Indonesia": 1 1 1 1 1 1 1 1 1 1 ...
>>  $ ID_1      : int  1264 1264 1264 1264 1264 1264 1264 1264 1264 1264 ...
>>  $ NAME_1    : Factor w/ 33 levels "Aceh","Bali",..: 11 11 11 11 11 11 11
>> 11 11 11 ...
>>  $ ID_2      : int  15418 15419 15420 15421 15422 15423 15424 15425 15426
>> 15427 ...
>>  $ NAME_2    : Factor w/ 391 levels "AcehBarat","AcehBaratDaya",..: 46 66
>> 75 76 87 93 109 131 137 143 ...
>>  $ VARNAME_2 : Factor w/ 83 levels "BanyuAsin","BaritoUtara",..: NA NA NA
>> NA NA NA 11 NA NA NA ...
>>  $ NL_NAME_2 : logi  NA NA NA NA NA NA ...
>>  $ HASC_2    : Factor w/ 386 levels "ID.AC.AB","ID.AC.AD
>> <http://id.ac.ad/>",..:
>>
>> 156 152 154 155 158 159 160 161 162 163 ...
>>  $ CC_2      : logi  NA NA NA NA NA NA ...
>>  $ TYPE_2    : Factor w/ 3 levels "Kabupaten","Kotamadya",..: 1 1 1 1 1 1
>> 1
>> 1 1 1 ...
>>  $ ENGTYPE_2 : Factor w/ 3 levels "Municipality",..: 2 2 2 2 2 2 2 2 2 2
>> ...
>>  $ VALIDFR_2 : Factor w/ 1 level "Unknown": 1 1 1 1 1 1 1 1 1 1 ...
>>  $ VALIDTO_2 : Factor w/ 2 levels "Present","Unknown": 1 1 1 1 1 1 1 1 1 1
>> ...
>>  $ REMARKS_2 : logi  NA NA NA NA NA NA ...
>>  $ Shape_Leng: num  1.18 2.09 2.24 2.77 4.6 ...
>>  $ Shape_Area: num  0.0609 0.159 0.0896 0.1426 0.1924 ...
>>
>> > write.dbf(Dmap, out.name="dmap.dbf", arcgis=FALSE)
>> Error in c(logical = "L", integer = "N", numeric = "F", character = "C",
>>  :
>>   invalid subscript type 'list'
>>
>> Is there an easier way that I could solve this (without editing the .dbf
>> files)? Alternately if I do have to edit the .dbf files how can I use the
>> write.dbf function (I don't think I can use convert.to.shapefile because I
>> can't import the .shp and .shx files into R until I've fixed the .dbf
>> file?)
>>
>> Thanks in advance for any suggestions,
>>
>> Best regards,
>> Amy
>>
>> --
>> *Amy Mikhail*
>> *EUPHEM fellow (European Program for Public Health
>> Microbiology)*<
>> http://www.ecdc.europa.eu/en/activities/training_activities/EUPHEM/Pages/index.aspx
>> >
>> Microbiology Reference Services
>> *Public Health England <http://www.gov.uk/phe>*
>>
>> 61 Colindale Avenue
>> London NW9 5EQ
>> UK
>>
>> Phone: +44 (0)208 32 *77295*
>> Mobile: +44 (0)781 4176107
>> Wmail: *Amy.Mikhail@phe.gov.uk*
>> Gmail: amy.mikhail@gmail.com
>>
>>         [[alternative HTML version deleted]]
>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>


-- 
*Amy Mikhail*
*EUPHEM fellow (European Program for Public Health
Microbiology)*<http://www.ecdc.europa.eu/en/activities/training_activities/EUPHEM/Pages/index.aspx>
Microbiology Reference Services
*Public Health England <http://www.gov.uk/phe>*
61 Colindale Avenue
London NW9 5EQ
UK

Phone: +44 (0)208 32 *77295*
Mobile: +44 (0)781 4176107
Wmail: *Amy.Mikhail@phe.gov.uk*
Gmail: amy.mikhail@gmail.com

	[[alternative HTML version deleted]]

