R data.table fread command : how to read large files with irregular separators?

后端 未结 5 1391
迷失自我
迷失自我 2020-12-06 20:49

I have to work with a collection of 120 files of ~2 GB (525600 lines x 302 columns). The goal is to make some statistics and put the results in a clean SQLite database.

5条回答
  •  一生所求
    2020-12-06 21:06

    Just committed to devel, v1.9.5. fread() gains strip.white argument with default TRUE (as opposed to base::read.table(), because it's more desirable). The example data is now added to tests.

    With this recent commit:

    require(data.table) # v1.9.5, commit 0e7a835 or more recent
    ans <- fread(" YYYY MM DD HH mm             19490             40790\n   1991 10  1  1  0      1.046465E+00      1.568405E+00")
    #      V1 V2 V3 V4 V5           V6           V7
    # 1: YYYY MM DD HH mm 19490.000000 40790.000000
    # 2: 1991 10  1  1  0     1.046465     1.568405
    sapply(ans, class)
    #          V1          V2          V3          V4          V5          V6          V7 
    # "character" "character" "character" "character" "character"   "numeric"   "numeric" 
    

提交回复
热议问题