Hello, I'm receiving an error on attempting to use the read.table() function to read in data from a tab-delimited file. The file has more than 60,000 rows with 94 tab-delimited columns. However, the error occurs on row 3 of the file:> wl <-read.table("sr003lines.tab", header=T, sep="\t")Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 3 did not have 94 elements On receiving this error, I wrote a python script to go through the file to find rows with fewer than the 94 columns -- python finds that the first row with fewer than 94 columns is 1,706 -- much later than what R reports. R keeps running into this problem even with my python-massaged input file that I know for sure contains only rows with 94 columns. I also copied the first 4 rows of the input file into a separate file -- R isn't able to get past this problem. I examined the row (line 3) of the input file -- the only thing that's unique about this line is that it contains a long string (236 characters) in a column that in the previous rows was empty. Any chance that this sort of thing would cause R to run into a road block? Thanks, Premal P. Vora Associate Prof. Finance Penn State Harrisburg
I'm guessing that there's something wrong with one of your column separators. Have you tried leaving out the 'sep="\t"' argument? -P Forafo San wrote:> Hello, > > I'm receiving an error on attempting to use the read.table() function > to read in data from a tab-delimited file. The file has more than > 60,000 rows with 94 tab-delimited columns. However, the error occurs > on row 3 of the file: > >> wl <-read.table("sr003lines.tab", header=T, sep="\t") > Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : > line 3 did not have 94 elements > > On receiving this error, I wrote a python script to go through the > file to find rows with fewer than the 94 columns -- python finds that > the first row with fewer than 94 columns is 1,706 -- much later than > what R reports. R keeps running into this problem even with my > python-massaged input file that I know for sure contains only rows > with 94 columns. > > I also copied the first 4 rows of the input file into a separate file > -- R isn't able to get past this problem. I examined the row (line 3) > of the input file -- the only thing that's unique about this line is > that it contains a long string (236 characters) in a column that in > the previous rows was empty. Any chance that this sort of thing would > cause R to run into a road block? > > Thanks, > Premal P. Vora > Associate Prof. Finance > Penn State Harrisburg > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >
Use the count.fields function to find out how many fields it thinks each row has. On Fri, Jun 19, 2009 at 5:50 PM, Forafo San<ppv.grps at gmail.com> wrote:> Hello, > > I'm receiving an error on attempting to use the read.table() function > to read in data from a tab-delimited file. The file has more than > 60,000 rows with 94 tab-delimited columns. However, the error occurs > on row 3 of the file: > >> wl <-read.table("sr003lines.tab", header=T, sep="\t") > Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, ?: > ?line 3 did not have 94 elements > > On receiving this error, I wrote a python script to go through the > file to find rows with fewer than the 94 columns -- python finds that > the first row with fewer than 94 columns is 1,706 -- much later than > what R reports. ?R keeps running into this problem even with my > python-massaged input file that I know for sure contains only rows > with 94 columns. > > I also copied the first 4 rows of the input file into a separate file > -- R isn't able to get past this problem. ?I examined the row (line 3) > of the input file -- the only thing that's unique about this line is > that it contains a long string (236 characters) in a column that in > the previous rows was empty. ?Any chance that this sort of thing would > cause R to run into a road block? > > Thanks, > Premal P. Vora > Associate Prof. Finance > Penn State Harrisburg > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Try comment.char='', quote='' You may have unbalanced quotes or comments (#) in your data. On Fri, Jun 19, 2009 at 5:50 PM, Forafo San <ppv.grps@gmail.com> wrote:> Hello, > > I'm receiving an error on attempting to use the read.table() function > to read in data from a tab-delimited file. The file has more than > 60,000 rows with 94 tab-delimited columns. However, the error occurs > on row 3 of the file: > > > wl <-read.table("sr003lines.tab", header=T, sep="\t") > Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, > : > line 3 did not have 94 elements > > On receiving this error, I wrote a python script to go through the > file to find rows with fewer than the 94 columns -- python finds that > the first row with fewer than 94 columns is 1,706 -- much later than > what R reports. R keeps running into this problem even with my > python-massaged input file that I know for sure contains only rows > with 94 columns. > > I also copied the first 4 rows of the input file into a separate file > -- R isn't able to get past this problem. I examined the row (line 3) > of the input file -- the only thing that's unique about this line is > that it contains a long string (236 characters) in a column that in > the previous rows was empty. Any chance that this sort of thing would > cause R to run into a road block? > > Thanks, > Premal P. Vora > Associate Prof. Finance > Penn State Harrisburg > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]