Skip to content
Prev 10505 / 398502 Next

"all rows must have the same length" error while using read.table

...
The number of columns in each row.  Apparently, it was different in
at least two rows.

Possible causes:
1)  repeated tabs, when there should've been one only.  From the 
format of the data you provided, this looks possible.  With \t 
representing a tab, R will interpret "3\t\t7" as a 3, two 
separators, with a non-value between them (NA), and a 7 rather 
than 3, separator, 7.  If you're comfortable with vi, you can find 
these in your file by ":s/\t\t" (without the quotes, of course).  
grep gets confused on my system between \t being a "t" and 
a tab.  If you're certain that there are no deliberately blank
entries (check this!), you can remove repeated tabs inside vi with
:1,$s,\t\t*,\t,g


2) trailing tabs.  Again, from within vi, you can clean these
up by 
:1,$s,[\t ]*,,  
which clears trailing spaces and tabs.

I usually leave a few perl, awk, or sed scripts lying around 
just for such tidy-ups (plus empty lines, leading spaces, and 
other annoyances).  Keeps me from having to remember all the
things that have bitten me before.

Cheers

Jason
Message-ID: <20010401151953.A5623@camille.indigoindustrial.co.nz>
In-Reply-To: <3AC6EA34.6080100@uol.com.br>; from hzi@uol.com.br on Sun, Apr 01, 2001 at 08:43:32AM +0000