.csv 파일을 R로 읽으려고 할 때 '불완전한 마지막 줄'경고
.csv 파일을 R로 읽고 다음 공식을 사용하려고합니다.
pheasant<-read.table(file.choose(),header=TRUE,sep=",")
이 경고 메시지가 나타납니다.
"incomplete final line found by readTableHeader on 'C:\Documents and Settings..."
이 경고의 원인이 될 수 있다고 생각한 몇 가지가 있지만, 안타깝게도 R에 대해 스스로 문제를 진단 할만큼 충분히 알지 못하기 때문에 다른 사람이 나를 대신해 진단 할 수 있기를 바라며 여기에 게시 할 것이라고 생각했습니다!
- .csv 파일은 원래 Excel 파일이었는데 .csv 형식으로 저장했습니다.
- 파일은 세 개의 데이터 열로 구성됩니다.
- 각 데이터 열의 길이가 다릅니다. 즉, 각 열에 다른 수의 값이 있습니다.
- 한 번에 두 열의 평균 (정규 분포에 따라 t- 검정 또는 동등한 분포를 사용하여)을 비교하고 싶습니다. 예를 들어 열 1 값과 열 2 값 사이의 t- 검정, 그런 다음 t- 열 1 및 열 3 값 테스트 등
어떤 도움이나 제안이라도 진지하게 감사하겠습니다!
이 메시지는 파일의 마지막 줄이 줄 끝 (EOL) 문자 (줄 바꿈 ( \n
) 또는 캐리지 리턴 + 줄 바꿈 ( \r\n
))로 끝나지 않음을 나타냅니다 . 이 메시지의 원래 의도는 파일이 불완전 할 수 있음을 경고하기위한 것입니다. 대부분의 데이터 파일에는 파일의 맨 마지막 문자로 EOL 문자가 있습니다.
해결책은 간단합니다.
- 파일 열기
- 파일의 맨 마지막 줄로 이동
- 해당 줄의 끝에 커서를 놓습니다.
- 프레스 return
- 파일 저장
문제는 해결하기 쉽습니다. 마지막 줄이 비어 있어야하기 때문입니다.
콘텐츠가
line 1,
line2
그것을 변경
line 1,
line2
(empty line here)
오늘 나는 아래 명령을 사용하여 R을 사용하여 JSON 파일을 읽으려고 할 때 이런 종류의 문제를 만났습니다.
json_data<-fromJSON(paste(readLines("json01.json"), collapse=""))
; 위의 방법으로 해결합니다.
.xls 파일이 아닌 .csv 파일을 선택 했습니까? .xls 파일을 읽으려고 할 때만 오류를 재현 할 수 있습니다. .csv 파일이나 다른 텍스트 파일을 읽으려고하면 발생하는 오류를 재현 할 수 없습니다.
> Data <- read.table("test.csv",header=T,sep=",")
> Data <- read.table("test.xlsx",header=T,sep=",")
Warning message:
In read.table("test.xlsx", header = T, sep = ",") :
incomplete final line found by readTableHeader on 'test.xlsx'
readTableHead
오류를 제공하는 c- 함수입니다. 데이터 유형을 결정하기 위해 처음 n 줄 (표준 처음 5 개)을 읽으려고합니다. 나머지 데이터는를 사용하여 읽습니다 scan()
. 따라서 문제는 파일 형식입니다.
알아내는 한 가지 방법은 작업 디렉토리를 파일이있는 디렉토리로 설정하는 것입니다. 그렇게하면 읽은 파일의 확장자를 볼 수 있습니다. Windows에서는 표준으로 표시되지 않는다는 것을 알고 있으므로 그렇지 않은 동안 csv라고 믿을 수 있습니다.
다음으로해야 할 일은 메모장이나 워드 패드 (또는 다른 편집기)에서 파일을 열고 형식이 내 파일과 동일한 지 확인하는 것입니다 test.csv
.
Test1,Test2,Test3
1,1,1
2,2,2
3,3,3
4,4,
5,5,
,6,
이 파일은 다음 데이터 프레임을 제공합니다.
> read.table(testfile,header=T,sep=",")
Test1 Test2 Test3
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 NA
5 5 5 NA
6 NA 6 NA
Excel에서 저장 한 csv 형식은 모든 셀을 쉼표로 구분합니다. 빈 셀에는 값이 없습니다. read.table()
쉽게 처리 할 수 있으며 빈 셀을 잘 인식합니다.
먼저 파일을 문자형 벡터로 읽으려면 readLines()
(와 함께 warn = FALSE
)를 사용 합니다.
그런 다음 text =
옵션을 사용하여 벡터를 데이터 프레임으로 읽습니다.read.table()
pheasant <- read.table(
text = readLines(file.choose(), warn = FALSE),
header = TRUE,
sep = ","
)
I realized that several answers have been provided but no real fix yet.
The reason, as mentioned above, is a "End of line" missing at the end of the CSV file.
While the real Fix should come from Microsoft, the walk around is to open the CSV file with a Text-editor and add a line at the end of the file (aka press return key). I use ATOM software as a text/code editor but virtually all basic text editor would do.
In the meanwhile, please report the bug to Microsoft.
Question: It seems to me that it is a office 2016 problem. Does anyone have the issue on a PC?
I received the same message. My fix included: I deleted all the additional sheets (tabs) in the .csv file, eliminated non-numeric characters, resaved the file as comma delimited and loaded in R v 2.15.0 using standard language:
filename<-read.csv("filename",header=TRUE)
As an additional safeguard, I closed the software and reopened before I loaded the csv.
In various European locales, as the comma character serves as decimal point, the read.csv2 function should be used instead.
The problem that you're describing occurred for me when I renamed a .xlsx
as .csv
.
What fixed it for me was going "Save As" and then saving it as a .csv
again.
I have solved this problem with changing encoding in read.table argument from fileEncoding = "UTF-16" to fileEncoding = "UTF-8".
I got this problem once when I had a single quote as part of the header. When I removed it (i.e. renamed the respective column header from Jimmy's data
to Jimmys data
), the function returned no warnings.
To fix this issue through R itself, I just used read.xlsx(..)
instead of a read.csv()
. Works like a charm!! You do not even have to rename. Renaming an xlsx into to csv is not a viable solution.
Open the file in text wrangler or notepad ++ and show the formating e.g. in text wrangler you do show invisibles. That way you can see the new line or tabs characters Often excel will add all sorts of tabs in the wrong places and not a last new line character, but you need to show the symbols to see this.
My work around was that I opened the csv
file in a text editor, removed the excessive commas on the last value, then saved the file. For example for the following file
Test1,Test2,Test3
1,1,1
2,2,2
3,3,3
4,4,
5,5,
,6,,
Remove the commas after 6, then save the file.
I've experienced a similar problem, however this appears to a generic warning, and may not in fact be related to the line-end character. In my case it was giving this error because the file I was using contained Cyrillic characters, once I replaced them with latin characters the error disappeared.
I tried different solutions, such as using a text editor to insert a new line and get the End Of Line character as recommended in the top answer above. None of these worked, unfortunately.
The solution that did finally work for me was very simple: I copy-pasted the content of a CSV file into a new blank CSV file, saved it, and the problem was gone.
'IT박스' 카테고리의 다른 글
Xcode 4.2 및 iOS 5 SDK를 사용할 때 이전 iOS 버전을 타겟팅 할 수 있습니까? (0) | 2020.08.15 |
---|---|
Fiddler를 사용하여 WCF 서비스를 모니터링하는 방법 (0) | 2020.08.15 |
Oracle SQL의 테이블에 대한 모든 제약 조건의 표시 이름 (0) | 2020.08.15 |
SSL 대체를 비활성화하고 .NET에서 아웃 바운드 연결에 TLS 만 사용하려면 어떻게해야합니까? (0) | 2020.08.15 |
모든 액티브 레코드가 싫어하는 이유는 무엇입니까? (0) | 2020.08.15 |