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

Jason Turner jasont at indigoindustrial.co.nz
Sun Apr 1 05:19:53 CEST 2001


>     I tried to read the table bellow (table goes on with 54 rows) with 
> the read.table
...
>   
> What "length" is the error message referring to? 

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
-- 
Indigo Industrial Controls Ltd.
64-21-343-545
jasont at indigoindustrial.co.nz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list