🎣®[R|报错]报错解决①EOF within quoted string

你在用R读取数据时,是否曾出现过这样的错误
Warning messages:
1: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : EOF within quoted string
2: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : number of items read is not a multiple of the number of columns

场景:我在读取一个两列的数据(884行,第一行为行名),读取命令为:

data<-read.table("data.txt",header = TRUE,sep = "\t",stringsAsFactors = FALSE)
code

data

出现了上方的Warning ,数据可以读取,但是读取的并不完整,只剩下452行,读入的这个数据明显不符合我们的预期。

修正后的代码:

data<-read.table("data.txt",header = TRUE,sep = "\t",stringsAsFactors = FALSE,quote = "")

在读取命令中增加了一个参数quote = "",读取完成,data包含883行,符合预期,可以使用。

扫描下方二维码关注生信客部落公众号:


生信客部落
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容