[R] Using sqldf() to read in .fwf files
HDoran at air.org
Mon Sep 15 18:09:07 CEST 2014
I am learning to use sqldf() to read in very large fixed width files that otherwise do not work efficiently with read.fwf. I found the following example online and have worked with this in various ways to read in the data
", file = "fixed")
fixed <- file("fixed")
sqldf("select substr(V1, 1, 1) f1, substr(V1, 2, 4) f2 from fixed")
I then applied this to my real world data problem though it yields the following error message and I am not sure how to interpret this.
dor <- file("dor")
> sqldf("select substr(V1, 1, 1) f1, substr(V1, 2, 4) f2 from dor")
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
line 1 did not have 6 elements
Looking at my .fwf. data in a text editor shows the data are structured as I would expect. In fact, I can read in the first few lines of the file using read.fwf and the data are as I would expect after being read into R.
[[alternative HTML version deleted]]
More information about the R-help