我需要将 .jsonl 文件读入 R,而且速度很慢。对于一个 67,000 行的文件,加载需要 10 多分钟。这是我的代码:
library(dplyr)
library(tidyr)
library(rjson)
f<-data.frame(Reduce(rbind, lapply(readLines("filename.jsonl"),fromJSON)))
f2<-f%>%
unnest(cols = names(f))
这是 .jsonl 文件的示例
{"UID": "a1", "str1": "Who should win?", "str2": "Who should we win?", "length1": 3, "length2": 4, "prob1": -110.5, "prob2": -108.7}
{"UID": "a2", "str1": "What had she walked through?", "str2": "What had it walked through?", "length1": 5, "length2": 5, "prob1": -154.6, "prob2": -154.8}
所以我的问题是:(1)为什么要花这么长时间才能运行,(2)我该如何解决?