Dear R users, I am trying to convert a dataset from one format to several rectangular datasets. A consultant helped design the data entry program for our survey using Delphi/Pascal and for each household the information is stored in a file called "EA-HM-HH.TXT" where EA is the enumeration area number, HM is the homestead number and HH is the household number. Within this file the data is stored as follows, ###### file="5677-001-001.TXT" ###### EAnumber=5677 HMnumber=001 HHnumber=001 # Demographics section Dserial=01 #first person in household Dage=56 Dsex=1 Dserial=02 #second person in household Dage=44 Dsex=2 Dserial=03 #second person in household Dage=7 Dsex=2 # Agricultural inputs section Amaize=200 Apumpkins=50 ###### end of file ######## Note that in the demograpics section there may only be less than 3 or more people in some households. I would like to create a file for the demographics section which is as follows EAnumber|HMnumber|HHnumber|Dserial|Dage|Dsex 5677 001 001 056 1 5677 001 001 044 2 5677 001 001 007 2 and for the agricultural inputs I would like to have, EAnumber|HMnumber|HHnumber|Amaize|Apumpkins 5677 001 001 0200 5677 001 001 0050 There are several similar files where the EA number, HM number or HH number changes, thus I would also like to know whether it is possible to create a script where for all household there is only one dataset for demographics, and one for agricultural inputs. Thanking you as always. Vumani Dlamini