Error reading a file: Error in scan line 6 did not have 63 elements

3

I'm new to R and can not 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 
    
asked by anonymous 04.04.2017 / 18:49

2 answers

1

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

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

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

to read the data. If the columns are separated by a 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 some other column separator is being used. If you still can not read the data, try opening the file in Excel, save a new version of it as .csv and read this new version using sep="," .

    
04.04.2017 / 19:18
0

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

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

Plus fread() is too fast!

    
06.04.2017 / 19:47