Re: [R] Partially reading a file (particularly)

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Tue, 29 May 2007 15:23:07 -0700

On Tue, 29 May 2007, Tobin, Jared wrote:

> Hello,
>
> I am trying to figure out if there exists some R command that allows one
> to be
> particularly selective when reading a file. I'm dealing with large
> fixed-width data
> sets that look like
>
> 539001..
> 639001..
> 639001..
> ...
> 539002..
> 639002..
> ...
>
> Presently, I am using read.fwf to read an entire file, but I am
> interested only in
> reading those records beginning with 5. I have been unable to find help
> in any of
> the suggested resources.

Assuming you have 'grep' in your path,

         res <- read.fwf( pipe( "grep '^5' my.file" ) , <other args> )

will do it.

grep will usually be found on linux/unix systems and Mac OS X. The 'Rtools' toolkit for windows has grep, I believe.

>
> I understand this is a SAS example that replicates what I'm looking to
> do, if it's of
> any help to anyone.
>
> street type name am
> traffic pm traffic
>
> freeway 408 3684
> 3459
> surface Martin Luther King Jr. Blvd. 1590 1234
> freeway 608 4583
> 3860
> freeway 808 2386
> 2518
> surface Lake Shore Dr. 1590 1234
>
> INPUT type $ @;
> IF type = 'surface' THEN DELETE;
> INPUT name $ 9-38 amtraff pmtraff;
>
> Any answers, suggestions, or points-in-the-right-direction would be much
> appreciated.
>
> --
>
> Jared Tobin, Student Research Assistant
> Dept. of Fisheries and Oceans
> tobinjr_at_dfo-mpo.gc.ca
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>

Charles C. Berry                        (858) 534-2098
                                          Dept of Family/Preventive Medicine
E mailto:cberry_at_tajo.ucsd.edu	         UC San Diego
http://biostat.ucsd.edu/~cberry/         La Jolla, San Diego 92093-0901

______________________________________________
R-help_at_stat.math.ethz.ch 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. Received on Tue 29 May 2007 - 22:26:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 May 2007 - 02:31:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.