Problems with reading a txt file (EOF within quoted string)

江枫思渺然 提交于 2019-11-28 05:19:53

问题


I am trying to use read.table() to import this TXT file into R (contains informations about meteorological stations provided by the WMO):

However, when I try to use

tmp <- read.table(file=...,sep=";",header=FALSE)

I get this error

eof within quoted string

warning and only 3514 of the 6702 lines appear in 'tmp'. From a quick look at the text file, I couldn't find any seemingly problematic characters.

As suggested in other threads, I also tried quote="". The EOF warning disappeared, but still only 3514 lines are imported.

Any advice on how I can get read.table() to work for this particular txt file?


回答1:


It looks like your data actually has 11548 rows. This works:

read.table(url('http://weather.noaa.gov/data/nsd_bbsss.txt'), 
    sep=';', quote=NULL, comment='', header=FALSE)

edit: updated according @MrFlick's comment's below.




回答2:


The problem is LF. R will not recognize "^M", to load the file, you only need to specify the encoding like this:

read.table("nsd_bbsss.txt",sep=";",header=F,encoding="latin1",quote="",comment='',colClasses=rep("character",14)) -> data 

But Line 8638 has more than 14 columns, which is different from other lines and may lead an error message.



来源:https://stackoverflow.com/questions/24679042/problems-with-reading-a-txt-file-eof-within-quoted-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!