读取txt文件时出现问题

时间:2019-03-29 21:34:32

标签: r

我想在R中向.txt文件发送文本,但我不断收到嵌入的null错误。

我尝试了以下代码:

text_df = read.delim2(testfile, header = TRUE, sep = ',')

原始文件(“ testfile”)如下所示:

UPC,HSY Item Description,Hsy Seasonal Segmentation,Store Nbr,Store Name,Building City,Building State/Prov,Building Postal Code,Store Type,WM Date,SeasonAndYear,OH_Qty,POS_Qty,POS_Sales
"0001070006638","Whprs Rbn Egg 13.75OZ","EAS $2.98 Candy Dish",1,"ROGERS, AR","ROGERS","AR","72756","Supercenter",1/27/2018 12:00:00 AM,"EAS2018",0,0,0.0000
"0001070006638","Whprs Rbn Egg 13.75OZ","EAS $2.98 Candy Dish",1,"ROGERS, AR","ROGERS","AR","72756","Supercenter",1/30/2018 12:00:00 AM,"EAS2018",0,0,0.0000
"0001070006638","Whprs Rbn Egg 13.75OZ","EAS $2.98 Candy Dish",1,"ROGERS, AR","ROGERS","AR","72756","Supercenter",2/2/2018 12:00:00 AM,"EAS2018",0,0,0.0000

我不断收到此错误:

  

警告消息:1:在read.table中(文件=文件,标头=标头,sep =   sep,quote = quote,:第1行似乎包含嵌入的null 2:   在read.table(file = file,header = header,sep = sep,quote = quote,   :第2行似乎包含嵌入的空值3:在read.table(file =   文件,标头=标头,sep = sep,引用=引用,:出现第3行   包含嵌入式null 4:在read.table(file = file,header =   标头,sep = sep,引用=引用,:第4行似乎包含   嵌入的空值5:在read.table(file = file,header = header,sep =   sep,quote = quote,:第5行似乎包含嵌入的null 6:   在scan(file = file,what = what,sep = sep,quote = quote,dec = dec,   :在输入中找到嵌入式nul

1 个答案:

答案 0 :(得分:0)

尝试一下:

df = read.table(yourFile, quote = '"', sep = ",", header = T)

这应该将“ ROGERS,AR”内的逗号视为字符串的一部分,而不是分隔符。