【发布时间】:2019-01-03 15:25:36
【问题描述】:
我正在尝试将多个 json 文件合并到一个数据库中,尽管尝试了在 SO 上找到的所有方法,但它失败了。
这些文件提供传感器数据。我完成的阶段是:
1. Unzip the files - produces json files saved as '.txt' files
2. Remove the old zip files
3. Parse the '.txt' files to remove some bugs in the content - random 3
letter + comma combos at the start of some lines, e.g. 'prm,{...'
我有代码可以将它们单独转换为数据帧:
stream <- stream_in(file("1.txt"))
flat <- flatten(stream)
df_it <- as.data.frame(flat)
但是当我把它放到一个函数中时:
df_loop <- function(x) {
stream <- stream_in(x)
flat <- flatten(stream)
df_it <- as.data.frame(flat)
df_it
}
然后尝试通过它:
df_all <- sapply(file.list, df_loop)
我明白了:
Error: Argument 'con' must be a connection.
然后我尝试将json文件与rbind.fill合并并合并无济于事。
不太确定我要去哪里如此严重的错误,因此非常感谢任何帮助。
【问题讨论】:
-
file.list是文件路径列表吗?在这种情况下,您需要在您的函数中执行stream <- stream_in(file(x)) -
这很好,但你能帮我理解为什么吗?
-
添加并请检查