[R] read dbf files into R

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Tue Sep 28 14:49:29 CEST 2004


Hisaji ONO wrote:

>  maptools:::dbf.read("test.dbf")
> 
>  maptools packages also has dbf.write, however it can only
> write out integer data.
> 

I'll stick my Rmap oar in. My Rmap package (not in CRAN) can access dbf
files using the dbf access library in shapelib. And instead of reading
the dbf file in, it creates a 'proxy' object that points to the dbf.

> admin <- dbfproxy("admin98.dbf")
Warning message:
Invalid names in DBF file, new names are:
 FIPS_ADMIN is now FIPS.ADMIN
GMI_ADMIN is now GMI.ADMIN
> names(admin)
 [1] "FIPS.ADMIN" "GMI.ADMIN"  "ADMIN.NAME" "FIPS.CNTRY" "GMI.CNTRY"
 [6] "CNTRY.NAME" "REGION"     "CONTINENT"  "POP.ADMIN"  "SQKM.ADMIN"
[11] "SQMI.ADMIN" "TYPE.ENG"   "TYPE.LOC"   "COLOR.MAP"
> dim(admin)
[1] 2604   14

 You can even subset it by rows and columns - it keeps the proxy nature
so the file doesn't change, the object just tracks the selected rows and
columns.

> admin
DBF proxy object, file is /home/rowlings/Geog/Maps/admin98.dbf
With 2604 rows and 14 columns
Selected from 2604 records with 14 items
> admin[1:4,]
DBF proxy object, file is /home/rowlings/Geog/Maps/admin98.dbf
With 4 rows and 14 columns
Selected from 2604 records with 14 items

 to get the actual data, use as.data.frame, or access columns with $NAME
syntax.

Of course Rmap is tricky to fully install, probably only works reliably
on Unix, leads to hair loss, etc etc.

Baz




More information about the R-help mailing list