I have large fixed width format dataset with multiple records with record number 1, 2, 3 and so on. I want to read all those records where record number is 1 using the select * sql statement. I'm using read.fwf function to import from the file but how to use sql statements with read.fwf function or any other alternative to read from fixed width format having some condition ?
Asked
Active
Viewed 670 times
0
-
1From the help file `?read.fwf`, it appears that this function is a wrapper to `read.table` and so can accept the arguments of this function. In `read.table`, you use the colClasses argument to specify the data type for each column. You can also feed it "NULL" when you want it to skip a column. Take a look at the discussion of colClasses in `?read.table` for a better idea. – lmo Oct 03 '17 at 12:33
-
An option may be to use `iotools::dstrsplit` with the `skip`, `strict`, `col_types` and `nrows` arguments to read in chunks at time and do the checks in R. `sqldf::read.csv2.sql` mentioned [here](https://stackoverflow.com/a/23197666/5861244) may do the job. I have not used the package though and I am not sure whether it will work a fixed format file. – Benjamin Christoffersen Oct 03 '17 at 17:16
-
The record numbers signify a different type of record? If not then you can load the whole file and the subset it any way you like. – Panos Rontogiannis Oct 04 '17 at 06:42
-
Yes the record number specifies different types of record. – Urvika Gupta Oct 04 '17 at 10:51
-
tried sqldf::read.csv2.sql but this does not understand the argument widths which i use for reading my fixed width format data – Urvika Gupta Oct 04 '17 at 10:53