在R中读取带分隔符的文本文件

时间:2017-05-23 19:43:32

标签: r file text

我有一个我正在尝试阅读的文本文件。请参阅下面的代码和错误消息。有人可以帮我阅读整个文本文件吗?

startingDir<-"C:/Desktop/"
thepattern <- "sample.txt" 
files <- list.files(path = startingDir,pattern = thepattern,recursive=T,full.names=T)
temp <- lapply(files, fread, sep="~",header = FALSE,fill= TRUE)
data <- rbindlist( temp )

错误:

Error in FUN(X[[i]], ...) : 
  Expecting 43 cols, but line 7 contains text after processing all cols.
  Try again with fill=TRUE. Another reason could be that fread's logic
  in distinguishing one or more fields having embedded sep='~' and/or
  (unescaped) '\n' characters within unbalanced unescaped quotes has
  failed. If quote='' doesn't help, please file an issue to figure out if the
  logic could be improved.

sample.txt的

2013~15~0001162~089~0100~0030~0081~01~0030~9970~                    ~A~ .6500~    12.8700~           ~     73.10~        530 ~        217 ~            ~      5,921 ~     29.0~ .333~    536~05302013~PL~07~010~L001~003~S~009~W~014~F001~000000011680905~0000536~0001240~0002~F002~000000011680908~0000536~0001240~0001
2013~15~0001164~029~0100~0110~0011~02~0030~9970~                    ~A~ .7000~     8.7800~     7.2200~    154.20~      5,421 ~      2,223 ~            ~     47,386 ~     50.0~1.000~      0~09302012~PL~07~010~L001~007~S~005~W~006
2013~15~0001164~123~0201~0030~0011~02~0030~9970~                    ~A~ .7000~     8.7800~     7.2200~    243.40~      9,260 ~      3,797 ~            ~     65,821 ~     44.0~1.000~   3294~10032012~PL~07~020~L001~006~S~006~W~017
2013~15~0001164~123~0202~0020~0011~02~0030~9970~                    ~A~ .7000~     8.7800~     7.2200~     96.30~      3,660 ~      1,501 ~            ~     24,858 ~     42.0~1.000~   3294~10012012~PL~07~030~L001~006~S~006~W~018
2013~15~0001164~123~0203~0050~0011~02~0030~9970~                    ~A~ .7000~     8.7800~     7.2200~     68.10~      2,581 ~      1,058 ~            ~     16,323 ~     39.0~1.000~   3294~10022012~PL~07~040~L001~007~S~007~W~001
2013~15~0001166~123~0102~0060~0011~02~0030~9970~                    ~A~ .7000~     8.7800~     7.2200~     77.00~        996 ~        408 ~      2,251 ~      8,037 ~     51.0~ .333~   4338~10222012~PL~07~010~L001~008~S~006~W~005~F001~000000012346193~0004338~0000193~0001
2013~15~0001166~123~0103~0030~0011~02~0030~9970~                    ~A~ .7000~     8.7800~     7.2200~     72.80~        949 ~        389 ~            ~      7,897 ~     53.0~ .333~   4338~10092012~PL~07~020~L001~008~S~006~W~018~F001~000000011800765~0004338~0000236~0002~F002~000000011809880~0004338~0000236~0007~F003~000000011809921~0004338~0000236~0009
2013~15~0001166~123~0101~0230~0081~02~0030~9970~                    ~A~ .6500~    12.8700~           ~      9.80~        131 ~         54 ~            ~        764 ~     28.0~ .333~   1778~05132013~PL~07~030~L001~007~S~006~W~032~F001~000000011808179~0004338~0000233~0003~F002~000000011808180~0004338~0000233~0005
2013~15~0001166~123~0102~0220~0081~02~0020~9970~                    ~A~ .6500~    12.8700~           ~     45.00~        826 ~        339 ~            ~      6,268 ~     50.0~ .333~      0~05132013~PL~07~040~L001~008~S~006~W~005~F001~000000012346193~0004338~0000193~0001
2013~15~0001173~089~0400~0140~0011~02~0030~9970~                    ~A~ .7500~     8.7800~     7.2200~     36.00~        952 ~        428 ~            ~      7,548 ~     53.0~ .600~   2451~10052012~PL~07~010~L001~005~S~009~W~025~F001~000000011368429~0004702~0008901~0012~F002~000000011368430~0004702~0008901~0014~F003~000000011368438~0004355~0008569~0001~F004~000000011368447~0004702~0008901~0010~F005~000000011369637~0004702~0008901~0009~F006~000000011369638~0004702~0008901~0011

0 个答案:

没有答案