[R] Import fixed-format ascii file with mixed record types

trece por ciento el13porciento at yahoo.com
Tue Feb 2 19:47:42 CET 2010


Thanks Jim,
As I know nothing about Perl (is it really necessary?), I think that I will try with David's approach.
What I want to do is to for a pseudo-panel with my survey data (that is collected periodically), and process it with the survey package. The resulting data set will be big (around 3.2 million records and 400 MBytes).
Hug

--- On Mon, 2/1/10, Jim Holtman <jholtman at gmail.com> wrote:

> From: Jim Holtman <jholtman at gmail.com>
> Subject: Re: [R] Import fixed-format ascii file with mixed record types
> To: "trece por ciento" <el13porciento at yahoo.com>
> Cc: "David Winsemius" <dwinsemius at comcast.net>, "r-help at r-project.org" <r-help at r-project.org>
> Date: Monday, February 1, 2010, 4:43 PM
> you probably need to split your file
> into several files according to the format. you can use
> something like perl or do it within R by doing readline and
> then separating the lines. you can use grep, split and
> textConnection to do most of the work.
> 
> What is the problem you are trying to solve?
> 
> Sent from my iPhone.
> 
> On Feb 1, 2010, at 14:33, trece por ciento <el13porciento at yahoo.com>
> wrote:
> 
> > Thanks David, but can read.fwf cope with different
> record types?
> > For example, if recordtype is the 4th character, I
> could have:
> > 
> > 011125678 ---> This is record Type 1
> > 011136779 ---> This is record Type 1
> > 011124943 ---> This is record Type 1
> > 011286711 ---> This is record Type 2
> > 011234872 ---> This is record Type 2
> > 011135628 ---> This is record Type 1
> > 
> > So, how can I tell read.fwf to take the correct type
> into account?
> > Thanks again,
> > Hug
> > 
> > --- On Mon, 2/1/10, David Winsemius <dwinsemius at comcast.net>
> wrote:
> > 
> > From: David Winsemius <dwinsemius at comcast.net>
> > Subject: Re: [R] Import fixed-format ascii file with
> mixed record types
> > To: "trece por ciento" <el13porciento at yahoo.com>
> > Cc: r-help at r-project.org
> > Date: Monday, February 1, 2010, 12:01 PM
> > 
> > 
> > On Feb 1, 2010, at 11:40 AM, trece por ciento wrote:
> > 
> >> I need to import several ascii files in fixed
> format with two different record types. The data comes from
> European Labor Force Surveys, wich is a household survey.
> The first record type is for people over 16 years, and the
> second much sorter is for people aged 15 or less (this
> record has a filler with several blanks to get the same
> record length).
> >> The files tipically have 160000 records, with 176
> characters per record, the data is numeric, corresponding to
> 102 variables, mostly integers (seven variables have two
> decimals). My opertating system is Windows XP.
> >> My questions:
> >> 1. Wich do you think is the best way to import the
> files into R?
> > 
> > 
> > ?read.fwf
> > 
> >> 2. Could you give me any references or examples?
> > 
> > There are examples in the help page.
> > 
> >> Thanking you in advance,
> >> Hug
> >> 
> >> 
> >> 
> >> 
> >>     [[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.
> > 
> > David Winsemius, MD
> > Heritage Laboratories
> > West Hartford, CT
> > 
> > 
> > 
> > 
> > 
> > 
> > ______________________________________________
> > 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