[R] read.table error

Steve Murray smurray444 at hotmail.com
Thu Sep 4 13:56:11 CEST 2008


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:


> Jan <- read.table("JanuaryAvBurntArea.txt", header=TRUE)
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:

> Jan <- read.table("JanuaryAvBurntArea.txt")
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



More information about the R-help mailing list