[R] How to read malformed csv files with read.table?

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Aug 22 19:22:58 CEST 2008


On Fri, 22 Aug 2008, Martin Ballaschk wrote:

> Hi folks,
>
> thank you for your friendly and immediate help!
>
> Am 22.08.2008 um 17:14 schrieb Prof Brian Ripley:
>> Or, better, use header=FALSE, skip=1 and the col.names arg of read.table().
>
> My solution is reading the files without the headers (skip = 1) and 
> seperately reading the headers with scan (scan("myfile.CSV", what = 
> "character", sep = "\t", nlines = 1). After throwing out the first two 
> columns it should be possible to assign the scanned colnames to the 
> data.frame colnames.

Yes, but if you read the header first you can set the col.names via the 
arg to read.table().

-- 
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