'Incomplete final line' warning when trying to read a .csv file into R
I'm trying to read a .csv file into R and upon using this formula:
pheasant<-read.table(file.choose(),header=TRUE,sep=",")
I get this warning message:
"incomplete final line found by readTableHeader on 'C:\Documents and Settings..."
There are a couple of things I thought may have caused this warning, but unfortunately I don't know enough about R to diagnose the problem myself so I thought I'd post here in the hope someone else can diagnose it for me!
- the .csv file was originally an Excel file, which I saved into .csv format
- the file comprises three columns of data
- each data column is of a differing length, i.e. there are a different number of values in each column
- I want to compare the means (using t-test or equivalent depending on normal / not normal distribution) of two of the columns at a time, so for example, t-test between column 1 values and column 2 values, then a t-test of column 1 and column 3 values, etc.
Any help or suggestions would be seriously appreciated!
Solution 1:
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 original intention of this message was to warn you that the file may be incomplete; most datafiles have an EOL character as the very last character in the file.
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
- Save the file
Solution 2:
The problem is easy to resolve; it's because the last line MUST be empty.
Say, if your content is
line 1,
line2
change it to
line 1,
line2
(empty line here)
Today I met this kind problem, when I was trying to use R to read a JSON file, by using command below:
json_data<-fromJSON(paste(readLines("json01.json"), collapse=""))
; and I resolve it by my above method.