[R] read.table

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Apr 2 09:01:16 CEST 2003


On Wed, 2 Apr 2003, Prof Brian Ripley wrote:

> On Tue, 1 Apr 2003 Oldradio69 at aol.com wrote:
> 
> > I am using read.table() to read in ASCII data into a data
> > frame.  The file has multiple columns that are not the
> > same length.  The function gives me errors, or I get 'NA'
> > characters in the blank fields.  I want to read these values
> > in to, e.g., perform a two-sample t-test.
> 
> You can't use read.table.  It is designed to read a data frame where by 
> definition the columns are the same length.
> 
> What you can do is to use scan and remove the NAs as in
> 
> tmp <- lapply(scan("foo.txt", list(0, 0)), function(x) x[!is.na(x)])
> 
> which will give you a list of two numeric vectors.
> 

Sorry, I omitted fill=TRUE from the scan call.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list