Jason Turner
2001-Apr-01 03:19 UTC
[R] "all rows must have the same length" error while using read.table
> 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
hzi
2001-Apr-01 08:43 UTC
[R] "all rows must have the same length" error while using read.table
Hi- I tried to read the table bellow (table goes on with 54 rows) with the read.table> AGE MONTH SEX HEADLEN HEADWTH NECK LENGTH CHEST > WEIGHT > 19 7 1 11.0 5.5 > 16.0 53.0 26.0 80 > 55 7 1 16.5 9.0 > 28.8 67.5 45.0 344 > 81 9 1 15.5 8.0 > 31.0 72.0 54.0 416 > 115 7 1 17.0 10.0 > 31.5 72.0 49.0 348 > 104 8 2 15.5 6.5 > 22.0 62.0 35.0 166> set3 <- read.table("/dos/mydocu~1/conjun~1.txt", header=T, sep="\t", row.names=1) R (1.2.2 under Linux) produced the following error message: Error in read.table("/dos/mydocu~1/conjun~1.txt", header=T, sep="\t", : all rows must have the same length. What "length" is the error message referring to? The names of the variables? Thanks in advance. Regards, Henry -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._