[R] Odp: importing csv gets me all 16,000 columns with "NA"

J.delasHeras at ed.ac.uk J.delasHeras at ed.ac.uk
Fri Oct 22 13:11:34 CEST 2010

Quoting Petr PIKAL <petr.pikal at precheza.cz>:

> There are many ways how to import whole file by read.* commands but you
> could also check scan or readLines functions. The result always depends on
> looklike of your input file (separators, decimals, missing values etc.)
> Regards
> Petr

When a file doesn't seem to read well, I just read it line by line using
'readLines', as Petr suggests.
That reads the whole file (or part of it if you choose that) on a  
per-line basis. Then you can explore these lines and see the  
structure... whether there are extra comment lines you didn't count  
on, or strange formatting... sometimes quotation marks can be  
problematic... or an apostrophe within a text cell... or tehre are  
characters present in teh middle of teh data that read* took as a  
comment mark...
doing readLines, then you can split each line as required (use 'strsplit')
It seems complicated, but when you're not exactly sure of the format  
of a file you've been given, or you get unexpected results, readLines  
is very useful and an extra 3-4 lines of code will sort the data after  
you have a look inside.


The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

More information about the R-help mailing list