Error reading file: Error in scan line 6 Did not have 63 Elements

Asked

Viewed 751 times

4

I’m a beginner in R and I can’t read the file I’m working with.

tab1<-read.table("savedrecs.txt", header=T, sep="\t") 
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
line 6 did not have 63 elements 
  • This is Stackoverflow in English. Questions must be asked in this language.

2 answers

2

Without having access to the file savedrecs.txt, it is impossible to give a definitive answer to this question. It is only possible to speculate. It seems that the problem lies in the argument sep="\t". This option indicates to R that your archive columns are separated by tab tags.

Open your file in Notepad (or some similar program) to find out how the columns are separated. Most likely they are separated by spaces. If so, use the command

tab1<-read.table("savedrecs.txt", header=T, sep=" ") 

to read the data. If the columns are separated by comma or semicolon, use

tab1<-read.table("savedrecs.txt", header=T, sep=",")
tab1<-read.table("savedrecs.txt", header=T, sep=";")

respectively.

It is very unlikely that any other column separator is being used. If it is still not possible to read the data, try to open the file in Excel, save a new version of it as .csv and read this new version using sep=",".

2

With the limitations we have to answer pointed out by @Marcus Nunes, I advise you to use the function fread() package data.table. The great advantage in this case is that you do not need to inform the delimiter or if there is header (header), because the function detects them automatically.

install.package('data.table')
library(data.table)
tab1 <- fread("savedrecs.txt") 

Moreover fread() is too fast!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.