[R] How to parse text file into a table?

Ben Bolker bolker at ufl.edu
Sun Feb 22 16:18:47 CET 2009


Daren Tan <darentan76 <at> gmail.com> writes:

> 
> I am given a text file of records to be converted into a table format.
> I have searched related topics or packages, but can't find any similar
> cases. Please help.
> 
> Sample record is given below. Take note the last element doesn't have
> a semi colon.
> 
> ###---------Start of record----------------------
> 
> Name : John
> Height: 170cm
> Weight  : 70kg
> Age: 30
> 
> Status: Married
> Children: 2
> 
> Employment  Engineer
> 
> ###---------End of record-----------------------
> 
> Table format should have this header
> Name	Height	Weight	Age	Status	Children	Employment


  You can put something together with
readLines, grep (to find the appropriate lines),
gsub (to strip off the first field) ... if you need
an explicit example, ask again ...

  Ben Bolker



More information about the R-help mailing list