Skip to content

read.table error

3 messages · Steve Murray, Brian Ripley

#
Dear all,

I have a tab-delimited text (.txt) file which I'm trying to read into R. This file is of column format - there are in fact 3 columns and 259201 rows (including the column headers). I've been using the following commands, but receive an error each time which prevents the data from being read in:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 1 did not have 6 elements


I tried removing the 'header' argument, but receive a similar message:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 2 did not have 6 elements


What's more confusing about this is that I know that none of the lines have 6 elements! They're not supposed to! Each row only has 3 values (one per column)!

As a final resort I tried 'scan':

 <- scan("JanuaryAvBurntArea.txt")
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  scan() expected 'a real', got 'Latitude'

...which is obviously something to do with there being a header as the first row, but the 'scan' command doesn't seem to have an equivalent of 'header=TRUE' like read.table...?


If anyone is able to shed some light on why I'm receiving these errors, and how I can get the data into R, then I'd be very grateful to hear them! I suspect I'm doing something very basic which is wrong!

Many thanks,

Steve




_________________________________________________________________
Win New York holidays with Kellogg?s & Live Search
#
On Thu, 4 Sep 2008, Steve Murray wrote:

            
How about telling R it is tab-delimited?  Use read.delim or at least 
sep="\t".

Also, see the footer to this message: we are not clairvoyant and cannot 
see the file unless you show us part of it.

With a file of that size you should study the 'R Data Import/Export 
Manual' and take some steps to read it in efficiently (e.g. specify 
nrows and colClasses).
I suspect there is whitespace in the 'values'.

  
    
#
Thanks Prof. Ripley! I knew it would be something simple - I'd missed the "\t" from the read.table command! I won't be doing that again...!!

Thanks again,

Steve