[R] Read text file subsetting rows

From: Zev Ross <zev_at_zevross.com>
Date: Fri, 11 Apr 2008 11:31:46 -0400


Hi All,

Can anyone direct me to a read function in R that will allow me to only read in rows of a text file that begin with a particular value such as the data below. I would read the entire file in and then limit, but the files were constructed such that the first two letters determine how many variables are in the row (different letters mean different numbers of columns and different column names/types).

I can do this in SAS, but I'd prefer to use R. The approximate SAS code is below with the key piece of code being "if rectype='RD'" then do.

Thoughts?

Zev

RD|I|01|073|0023|68103|5|7|017|810|20070103|00:00|0.6||3|||||||||||||
RD|I|01|073|0023|68103|5|7|017|810|20070106|00:00|9.5||3|||||||||||||
RD|I|01|073|0023|68103|5|7|017|810|20070109|00:00|2.5||3|||||||||||||
RD|I|01|073|0023|68103|5|7|017|810|20070112|00:00|13.7||3|||||||||||||
RD|I|01|073|0023|68103|5|7|017|810|20070115|00:00|7.3||3|||||||||||||
RA|I|01|073|0023|A334|5|7|017|810|20070118|00:00|3.7||3|||||||||||||
RD|I|01|073|0023|68103|5|7|017|810|20070121|00:00|6.9||3|||||||||||||
RC|I|01|073|0023|Quer|5|7|017|810|20070124|00:00|1.8||3|||||||||||||


infile 'C:\junk\RD_501_88101_2006-0.txt'  dlm='|' firstobs=3 missover;
 rectype $2. @;
if rectype = 'RD' then do;

-- 
Zev Ross
ZevRoss Spatial Analysis
303 Fairmount Ave
Ithaca, NY 14850
607-277-0004 (phone)
866-877-3690 (fax, toll-free)
zev_at_zevross.com

______________________________________________
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.
Received on Fri 11 Apr 2008 - 15:37:45 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 Fri 11 Apr 2008 - 17:30:27 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.

list of date sections of archive