[R] question about read datafile
jim holtman
jholtman at gmail.com
Tue Dec 23 01:49:00 CET 2008
Read in the data using readLines to read the complete line. Use
grep/regexpr to scan for valid lines and then convert them to numeric
by using strsplit/as.numeric.
On Mon, Dec 22, 2008 at 2:13 PM, Lu, Zheng <Zheng.Lu at mpi.com> wrote:
> Dear all:
>
>
>
> I have been thinking to import below one data file (.txt)into R by
> read.table(..,skip=1, header=T). But How can I deal with the repeated
> rows of TABLE NO.1 and names of data variables in the middle of this
> data file. The similar block will be repeated 100 times, here only show
> 4 of them and within each block, data records also can vary, here only
> paste 4 rows for example. I appreciate your consideration and help in
> this holiday season. Happy Holiday!
>
>
>
> TABLE NO. 1
>
> ID GID TIME OBS AMT EVID
> RATE ADDL II CMT WT IPRE
>
> 3.1000E+01 1.0000E+00 0.0000E+00 0.0000E+00 1.0000E+00 1.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 3.3918E+02
>
> 3.1000E+01 1.0000E+00 0.0000E+00 2.0500E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 2.6267E+02
>
> 3.1000E+01 1.0000E+00 9.6000E+01 4.2100E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 3.1781E+02
>
> TABLE NO. 1
>
> ID GID TIME OBS AMT EVID
> RATE ADDL II CMT WT IPRE
>
> 3.1000E+01 1.0000E+00 0.0000E+00 0.0000E+00 1.0000E+00 1.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 5.7557E+01
>
> 3.1000E+01 1.0000E+00 0.0000E+00 2.0500E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 8.8583E+01
>
> 3.1000E+01 1.0000E+00 9.6000E+01 4.2100E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 1.7342E+02
>
> 3.1000E+01 1.0000E+00 1.6800E+02 5.3100E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 2.0179E+02
>
> TABLE NO. 1
>
> ID GID TIME OBS AMT EVID
> RATE ADDL II CMT WT IPRE
>
> 3.1000E+01 1.0000E+00 0.0000E+00 0.0000E+00 1.0000E+00 1.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 1.4389E+02
>
> 3.1000E+01 1.0000E+00 0.0000E+00 2.0500E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 2.6147E+02
>
> 3.1000E+01 1.0000E+00 9.6000E+01 4.2100E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 2.2634E+02
>
> 3.1000E+01 1.0000E+00 1.6800E+02 5.3100E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 4.0733E+02
>
> TABLE NO. 1
>
> ID GID TIME OBS AMT EVID
> RATE ADDL II CMT WT IPRE
>
> 3.1000E+01 1.0000E+00 0.0000E+00 0.0000E+00 1.0000E+00 1.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 2.2003E+02
>
> 3.1000E+01 1.0000E+00 0.0000E+00 2.0500E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 3.2116E+02
>
> 3.1000E+01 1.0000E+00 9.6000E+01 4.2100E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 3.3642E+02
>
> 3.1000E+01 1.0000E+00 1.6800E+02 5.3100E+02 0.0000E+00 0.0000E+00
> 0.0000E+00 0.0000E+00 0.0000E+00 4.0000E+00 2.4000E-02 4.7881E+02
>
> ...
>
> ...
>
> ...
>
>
>
> zheng
>
>
>
>
>
>
>
>
> This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you.
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list