【发布时间】:2019-05-04 20:37:54
【问题描述】:
假设我有超过 20M 行的非常大的 TSV 文件,如下所示:
a b {"condition1":["ABC"], "condition3":false, "condition4":4000}
c c {"condition1":["BBB"],"condition2":true}
我需要它看起来像:
Var1 Var2 Condition1 Condition2 Condition3 Condition4
a b ABC NA FALSE 4000
c c BBB TRUE NA NA
我尝试了以下代码,但它是: 一种。效率低下 湾。不工作
在阅读时分离第三列的现成解决方案?
dt<-fread(input = ifilename, header = T,encoding = "UTF-8" )
output<-dt[,c("filter")] #assume the third column named "filter"
fwrite(x = output,file = "./DB/filter.csv",)
filter.db<-fread(input ="./DB/filter.csv",fill=T)
【问题讨论】:
-
你确定你有
TRUE而不是true或True吗?这些数据看起来很像 JSON 或 python 字典,并且有许多工具可以解析这些对象(例如jsonlite包)。 -
你说得对,我编辑了。
-
一次一件事! 1.读取数据。 2. 列拆分/json 解析 3. 添加回data.frame
标签: r data.table fread