在R中读取具有不同行长度的文本文件

时间:2017-09-18 16:38:40

标签: r

我有一个超过60,000行的文本文件,我需要阅读。我使用了fread函数,我的代码如下。 (示例如下所示的两行)。我需要一个输出,如“输出”表中所示。

有人可以帮助我获得我想要的输出。任何帮助表示赞赏。

library(data.table)
file1 <- 'sample.txt'
data <- fread(file1)

Error:

Error in fread(in_file1) : 
  Expecting 13 cols, but line 20 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.


1999~24~0000049~079~0119~0780~0011~90~0030~9970~                    ~A~ .6500~     3.3000~           ~          ~            ~            ~            ~            ~         ~1.000~  2029 ~00000000~PL~01~210~L001~061~N~023~W~035
1999~24~0000049~079~0100~0860~0041~44~0030~0160~    BUEUPT          ~A~ .7000~     2.4000~     1.9600~    279.90~      7,503 ~      4,059 ~     44,237 ~     70,536 ~    150.0~1.000~   629 ~05111999~PL~01~220~L001~061~N~022~W~020~L002~061~N~022~W~021~L003~061~N~022~W~029~L004~060~N~022~W~016~L005~060~N~022~W~021

输出:

    1999~24~0000049~079~0119~0780~0011~90~0030~9970~                    ~A~ .6500~     3.3000~           ~          ~            ~            ~            ~            ~         ~1.000~  2029 ~00000000~PL~01~210~L001~061~N~023~W~035
    1999~24~0000049~079~0100~0860~0041~44~0030~0160~    BUEUPT          ~A~ .7000~     2.4000~     1.9600~    279.90~      7,503 ~      4,059 ~     44,237 ~     70,536 ~    150.0~1.000~   629 ~05111999~PL~01~220~L002~061~N~022~W~021
    1999~24~0000049~079~0100~0860~0041~44~0030~0160~    BUEUPT          ~A~ .7000~     2.4000~     1.9600~    279.90~      7,503 ~      4,059 ~     44,237 ~     70,536 ~    150.0~1.000~   629 ~05111999~PL~01~220~L003~061~N~022~W~029
    1999~24~0000049~079~0100~0860~0041~44~0030~0160~    BUEUPT          ~A~ .7000~     2.4000~     1.9600~    279.90~      7,503 ~      4,059 ~     44,237 ~     70,536 ~    150.0~1.000~   629 ~05111999~PL~01~220~L004~060~N~022~W~016
    1999~24~0000049~079~0100~0860~0041~44~0030~0160~    BUEUPT          ~A~ .7000~     2.4000~     1.9600~    279.90~      7,503 ~      4,059 ~     44,237 ~     70,536 ~    150.0~1.000~   629 ~05111999~PL~01~220~L005~060~N~022~W~021

0 个答案:

没有答案