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

Daniel Folkinshteyn dfolkins at gmail.com
Fri Aug 22 17:04:31 CEST 2008


on 08/22/2008 10:19 AM Martin Ballaschk said the following:
> how do I read files that have two header fields less than they have 
> columns? The easiest solution would be to insert one or two additional 
> header fields, but I have a lot of files and that would be quite a lot 
> of awful work.
> 
> Any ideas on how to solve that problem?
> 

you could use read.table with "header = F", that way it will read the 
table without worrying about column names (they will end up in the first 
row of the data).

Then, you can just delete the first row, or assign it to names(), or 
whatever.

if all the columns in all your files have the same names, you can read 
them all with header=F and col.names=vectorofcolumnnames, and then 
delete first row (which will contain the incomplete col names from the 
file).

hope this helps :)



More information about the R-help mailing list