RE: [R] converting an ASCII file to a matrix

From: Berton Gunter <>
Date: Wed 11 May 2005 - 02:07:20 EST


Ah ... the bane of real data analysts everywhere: getting the data from its original format into (R )- usable form for data analysis

This has nothing to do with R-WinEdit, AFAICS.

My approach would be to simply use readLines() to read the lines in as character strings and then process them by grep and/or regexpr() to extract the bits I wanted. If the formatting is fixed, substring() may also be useful. You will also need to convert the resulting character representation of numerics to numerics via as.numeric().

If you haven't worked through regular expressions before (?regexp), you will find this a bit of a chore; but it is well worth the effort, as they are invaluable for this sort of thing. There are numerous web tutorials to help (google on 'regular expressions').


"The business of the statistician is to catalyze the scientific learning process." - George E. P. Box    

> -----Original Message-----
> From:
> [] On Behalf Of Michael Graber
> Sent: Tuesday, May 10, 2005 8:45 AM
> To:
> Subject: [R] converting an ASCII file to a matrix
> Dear R-WinEdit users,

> I got a simple question, but somehow I cannot find the
> answer, although
> I have
> tried a lot!
> I got an ASCII-file and I want to import it into R, so that every
> character is defined by [i;j].
> The rows are not of the same length.
> the file looks like the following shortened abstract example:
> name: xxxxx xxxx
> age: 9.9.99
> record number: 999
> title: xxxxx xxxx xxx
> keywords: xxx xx
> "white space"
> name: yyyy yyyyyyyyyyyy
> age: 8.8.88
> record number: 8
> title: yyyy yy yyyy
> keywords: yyyyyyyyyyy yyyyyyyy yyy
> "white space"
> I would be very grateful for your help!
> Michael Graber
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!
> mailing list PLEASE do read the posting guide! Received on Wed May 11 02:13:29 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:41 EST