[R] read.table

Tilo Blenk tilo.blenk at charite.de
Sat Feb 26 12:41:56 CET 2005


Maybe argument 'fill' of read.table is the solution.

The default value is FALSE in read.table and, therefore, any line not 
having the same number of fields as the first line (not skipped) will 
make problems. If set to TRUE, as in read.delim and read.csv, lines 
with less number of fields get blank fields added at the end.

If exporting tab delimited text files from Excel lines with empty 
fields at the end in the Excel file often have less fields than the 
header line in the text file. Reading them with read.delim fixes that.

If the problem is more complicated you probably need to find the lines 
with count.fields and correct them manually.

You can find them (actually the line number) with something like

which(count.fields('data.txt') != count.fields('data.txt')[1])

assuming that the first line has the correct number of fields.

Tilo




More information about the R-help mailing list