[R] Importing ASCII flat
David Winsemius
dwinsemius at comcast.net
Thu May 17 16:09:27 CEST 2012
On May 17, 2012, at 8:17 AM, Richard Iles wrote:
> I am trying to import Indian National Sample Survey Data. It is
> ASCII flat
> and an example is below
>
> 001460306025001117101011117111201*01*000000211 270104070204093
> 002460306025001117101011117111201*02*0000008011116104910519572 022
> 2600
> 1150 30 55 170 4005 003460306025001117101011117111201*03*
> 0000111039204112 222
>
> Previous post don't seem to provide much help. I have an document
> outlining
> the layout of the data, but don't know how to start. An example of the
> layout is that the values in bold indicate separate levels.Example of
> layout is below:
>
Your data layout was mangled by passage of html formating through
various mailers. Looking at:
http://mospi.nic.in/Mospi_New/site/inner.aspx?status=4&menu_id=67
... I'm guessing you are showing only a tiny slice of the data
specification.
> Sl.No. Item Blk Item Col Len Byte Position Remarks
> 1 Common Items 33 1 - 33 Auto-duplicated
> 2 Level 2 34 - 35 "02" Generated
> 3 Filler 5 36 - 40 "00000" Generated
> 4 HHS Size 3 1 2 41 - 42
> 5 NIC Code(5-digit) 3 2 5 43 - 47
> 6 NCO Code(3-digit) 3 3 3 48 - 50
> 7 HHS type 3 4 1 51 -51
> 8 Religion 3 5 1 52 - 52
That was my best guess at what might have originally been the fixed
format layout. You should look at:
?utils::read.fwf
If you can create a data.frame, dfrm, from that data layout, then the
most useful fields would be the names and the lengths. Perhaps this
could work
read.fwf(file, widths=dfrm$Len, col.names= dfrm$Item)
> As is obvious, I am relatively new to R.
> Any constructive advice would be
> welcome.
PLEASE, please, please : Learn to post in plain text.
>
> Richard Iles
> --
> Economics Ph.D. student
> Delhi School of Economics (visiting)
> e: richard.iles at griffithuni.edu.au
>
> website: https://sites.google.com/a/griffithuni.edu.au/richard-iles/home
> <https://sites.google.com/site/richardileshome/home>
>
> [[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
West Hartford, CT
More information about the R-help
mailing list