Reputation: 3502
I'm trying to import .dbf
file into RStudio.
This file is the attribute table of a shapefile that I exported as .dbf
.
You can find the .dbf
file in this link
I tried importing it as below
library(foreign)
df <- read.dbf("5layers1.dbf")
I got errors (below) and RStudio crashed so I couldn't get sessionInfo()
.
Any suggestions how to import this large .dbf file into RStudio will be highly appreciated.
Upvotes: 2
Views: 3661
Reputation: 3393
Similar to the OP, I found that foreign::read.dbf
crashed my session. However I was able to use the rio
package without any problems:
df <- rio::import("5layers1.dbf")
Upvotes: 1
Reputation: 3200
For me read.dbf()
didn't work neither and the files are usually too big to open it in excel to convert them into something more usable. I find a better way to read in .dbf files is to use the dbf ODBC Driver distributed under Windows (usually only 32-bit version), given you operate under Windows, and create a connection together with the RODBC
and ultimately access the data as in the usual way you connect to a database. Now, one would need to use the 32-bit version of R so it´s compatible with the driver architecture, but R comes with both 32 and 64 bit versions.
Upvotes: 1
Reputation: 1664
I suggest to save it as a csv-file (I did this with LibreOffice
in one or two hours and use ;
as a separator). After you can import it to R
like this:
dat <- readLines("5layers1.csv")
li <- strsplit(dat, ";")
num <- as.numeric(unlist(lapply(li, `[[`, 100)))
boxplot(num, main=unlist(strsplit(dat[1], ";"))[100])
mtext(side=3, text=paste("n = ", length(num), sep=""))
Its really a big file! You will have a lot of fun with this! I'm not sure if R is the tool for this job. I use a Tinkpad T430 with 8GB Ram and it need 2min for run this five lines to make this boxplot, which present one of the 179 attributes of your dbf-file:
Upvotes: 1