你在用R讀取數(shù)據(jù)時,是否曾出現(xiàn)過這樣的錯誤
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
場景:我在讀取一個兩列的數(shù)據(jù)(884行,第一行為行名),讀取命令為:
data<-read.table("data.txt",header = TRUE,sep = "\t",stringsAsFactors = FALSE)

code

data
出現(xiàn)了上方的Warning ,數(shù)據(jù)可以讀取,但是讀取的并不完整,只剩下452行,讀入的這個數(shù)據(jù)明顯不符合我們的預(yù)期。
修正后的代碼:
data<-read.table("data.txt",header = TRUE,sep = "\t",stringsAsFactors = FALSE,quote = "")
在讀取命令中增加了一個參數(shù)quote = "",讀取完成,data包含883行,符合預(yù)期,可以使用。
掃描下方二維碼關(guān)注生信客部落公眾號:

生信客部落