Hello R wizards,

What is the best way to read a data file containing both fixed-width and 
tab-delimited files? (More detail follows.)

_*Details:*_
The U.S. Bureau of Labor Statistics provides local area unemployment 
statistics at ftp://ftp.bls.gov/pub/time.series/la/, and the data are 
documented in the file la.txt 
<ftp://ftp.bls.gov/pub/time.series/la/la.txt>. Each data file has five 
tab-delimited fields:

    * series_id
    * year
    * period (codes for things like quarter or month of year)
    * value
    * footnote_codes

The series_id consists of five fixed-width subfields (length in 
parentheses):

    * survey abbreviation (2)
    * seasonal code (1)
    * area type code (2)
    * area code (6)
    * measure code (2)

So an example record might be:

LASPS36040003   1990    M01     8.8     L

I want to read in the data in one pass and convert them to a data frame with 
the following columns (actual name, class in parentheses):

    Survey abbreviation (survey, character)
    Seasonal (seasonal, logical seasonal=T)
    Area type (area_type_code, factor)
    Area (area_code, factor)
    Measure (measure_code, factor)
    Year (year, Date)
    Period (period, factor)
    Value (value, numeric)
    Footnote (footnote_codes, character but see note)

(Regarding the Footnote, I have to look at the data more. If there's 
just one code per record, this will be a factor; if there are multiple, 
it will either be character or a list. For not I'm making it only 
character.)

Currently I can read the data just fine using read.table, but this makes 
series_id the first variable. I want to break out the subfields as 
separate columns.

Any suggestions?

Thanks.
     Marsh Feldman




        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to