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

Martin Ballaschk tmp082008 at ballaschk.com
Fri Aug 22 16:19:15 CEST 2008


Hi,

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?

#######
R stuff:

 > read.table("myfile.CSV", sep = "\t", header = T)
   Error in read.table("myfile.CSV", sep = "\t",  :
   more columns than column names

 > count.fields("myfile.CSV", sep = "\t")
    [1] 10 12 12 12 12 12 12 12 12 12 12 [...]

#######
ugly sample ("Exported by SDL DataTable component"):

	time/ms	C550.KMS	Cyt_b559.KMS	Cyt_b563.KMS	Cyt_f_.KMS	P515FR.KMS	 
Scatt.KMS	Zea2.KMS	PC	P700
0	Point1	    -599.500	       0.000	       0.000	       0.000	        
0.000	       0.000	       0.000	       0.000	       0.000	       0.000
0	Point2	    -598.000	      -0.012	      -0.013	       0.040	        
0.013	       0.027	       0.010	       0.022	       0.000	       0.000
0	Point3	    -596.500	      -0.015	      -0.015	       0.044	        
0.020	       0.025	       0.010	       0.033	       0.000	       0.000
[...]


Cheers,
Martin



More information about the R-help mailing list