当我使用r来读取txt文件时,我将read.table sep para设置为sep =" \ 001"或sep =" \\ 001"两者都不起作用。
V1
1 886153044351\0010981623127\001\00113036806119\00113036806119
2 132693697611\0010\00118380389386\00113795105928\00113795105928
3 886134400554\0010981623127\001\00115033907649\00115033907649
4 550075776697\00115955516598\00115955516598\00113969121085\001
5 886156798054\0010918770552\001\00115977055775\00115977055775
6 132642200735\00118015668803\00118015668803\00118655109444\00118655109444
以上是我使用读表默认为R. 我使用split函数,但它也不适用于上面的sep。
在notepad ++中,我用逗号","替换\ 0001,所以我可以像数据帧一样将数据读入R中。
如果数据很大,我不能用notepad ++替换nul字符,我该怎么办呢?
答案 0 :(得分:1)
我没有设法从文件中使用@Colin Fay的解决方案。
解决方案是:
\001
在R中这样:
library(readr)
rawfile <- read_file("txt001sep.txt")
rawfile_csv <- gsub("\\\\001", ",", rawfile)
write_file(rawfile_csv, "myfile.csv")
read_csv("myfile.csv", col_names=FALSE)
答案 1 :(得分:0)
请尝试使用read.delim
功能:
read.delim(
text = "V1
1 886153044351\0010981623127\001\00113036806119\00113036806119
2 132693697611\0010\00118380389386\00113795105928\00113795105928
3 886134400554\0010981623127\001\00115033907649\00115033907649
4 550075776697\00115955516598\00115955516598\00113969121085\001
5 886156798054\0010918770552\001\00115977055775\00115977055775
6 132642200735\00118015668803\00118015668803\00118655109444\00118655109444",
sep = "\001", header = FALSE )
V1 V2 V3 V4 V5
1 V1 NA NA NA NA
2 1 886153044351 981623127 NA 13036806119 13036806119
3 2 132693697611 0 18380389386 13795105928 13795105928
4 3 886134400554 981623127 NA 15033907649 15033907649
5 4 550075776697 15955516598 15955516598 13969121085 NA
6 5 886156798054 918770552 NA 15977055775 15977055775
7 6 132642200735 18015668803 18015668803 18655109444 18655109444