Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In read.table(): incomplete final line found by readTableHeader

Tags:

r

csv

read.table

I have a CSV when I try to read.csv() that file, I get the warning warning message:

In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on ...

And I cannot isolate the problem, despite scouring StackOverflow and R-help for solutions.

This is the Dropbox link for the data: https://www.dropbox.com/s/h0fp0hmnjaca9ff/PING%20CONCOURS%20DONNES.csv

like image 453
user3351370 Avatar asked Mar 04 '14 12:03

user3351370


People also ask

What does incomplete final line mean in R?

The “incomplete final line” error message arises when there is a “missing” return in the last data row of your CSV file. You need to add an extra line-feed at the end of the file. There are two ways you can set about this: Open the file in a text editor and add an extra line. Then import the file to R.

How do I read a csv file in R?

In order to get a . csv file into R, you can use read. csv, and as the only argument, put the path to the file you want to read in within quotation marks.


3 Answers

As explained by Hendrik Pon,The message indicates that the last line of the file doesn't end with an End Of Line (EOL) character (linefeed (\n) or carriage return+linefeed (\r\n)).

The remedy is simple:

  • Open the file
  • Navigate to the very last line of the file
  • Place the cursor the end of that line
  • Press return/enter
  • Save the file

so here is your file without warning

df=read.table("C:\\Users\\Administrator\\Desktop\\tp.csv",header=F,sep=";")  df     V1               V2               V3               V4               V5               V6               V7               V8               V9              V10 1 Date 20/12/2013 09:04 20/12/2013 09:08 20/12/2013 09:12 20/12/2013 09:16 20/12/2013 09:20 20/12/2013 09:24 20/12/2013 09:28 20/12/2013 09:32 20/12/2013 09:36 2    1           1,3631           1,3632           1,3634           1,3633            1,363           1,3632           1,3632           1,3632           1,3629 3    2          0,83407          0,83408          0,83415          0,83416          0,83404          0,83386          0,83407          0,83438          0,83472 4    3           142,35           142,38           142,41            142,4           142,41           142,42           142,39           142,42            142,4 5    4           1,2263          1,22635          1,22628          1,22618          1,22614          1,22609          1,22624          1,22643           1,2265 

But i think you should not read in this way because you have to again reshape the dataframe,thanks.

like image 149
Aashu Avatar answered Sep 22 '22 17:09

Aashu


I faced the same problem while creating a data matrix in notepad. So i came to the last row of data matrix and pressed enter. Now i have a "n" line data matrix and a new blank line with cursor at the starting of "n+1" line. Problem solved.

like image 34
aditya harbola Avatar answered Sep 22 '22 17:09

aditya harbola


This is not a CSV file, each line is a column, you can parse it manually, e.g.:

file <- '~/Downloads/PING CONCOURS DONNES.csv'
lines <- readLines(file)
columns <- strsplit(lines, ';')
headers <- sapply(columns, '[[', 1)
data <- lapply(columns, '[', -1)
df <- do.call(cbind, data)
colnames(df) <- headers
print(head(df))

Note that you can ignore the warning, due that the last end-of-line is missing.

like image 34
Karl Forner Avatar answered Sep 24 '22 17:09

Karl Forner