[R] reading data from multiple files with multiple header

Jim Holtman jholtman at gmail.com
Wed Aug 31 05:14:34 CEST 2011


use readLines to read in the entire file, find your pattern of where your data starts and then write the data starting there using writeLines to a temporary file and now you can just read in that file using read.table; you will have 'skipped' the extra header data.

Sent from my iPad

On Aug 30, 2011, at 22:23, Julius Tesoro <jutesoro at yahoo.com> wrote:

> Dear All,
> 
> 
> I have many files with a lot of headers and text at the beginning of the file. The headers are not uniform though and they contain different sizes Is there a way where I can read a table and skip all of the headers/text on top of it until I encounter a certain text pattern? Here is an example. I just want to read the table after the ~A. 
> 
> 
> ~Version Information
>  VERS.              2.00:     CWLS log ASCII Standard -VERSION 2.00
>  WRAP.                NO:     One line per depth step
> #
> #
> ~Well Information Block
> #MNEM.UNIT     Data Type                      Description
> #---------     -----------                    ----------------
>  STRT.M             51.000                    :START DEPTH    
>  STOP.M               .010                    :STOP DEPTH     
>  STEP.M              -.010                    :STEP           
> #
> #
> ~Curve Information Block
> #MNEM.UNIT                        Curve Description
> #---------                        -----------------------------
>  DEPT.M                           :DEPTH
>  GRDE.GAPI                        :GAMMA FROM DENSITY TOOL 
>  CODE.G/C3                        :COMPENSATED DENSITY     
> #
> 
> #
> #
> ~A  Depth       GRDE       CODE       LSDU       BRDU       CADE       DENL       DENB       ADEN       VL2F       VL4F       VL6F       VL2A
>     51.000    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25
>     50.990    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25
>     50.980    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25
>     50.970    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25
>     50.960    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25
>     50.950    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25
>     50.940    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list