【发布时间】:2020-10-06 01:36:26
【问题描述】:
我有多个包含日期的 .json 文件。我想在 R 中导入所有 .json 文件以创建一个数据框并添加包含文件名的列。
2020-06-15.json:
[{"title":"Moral Machine","title_link":"http://moralmachine.mit.edu/"}]
2020-06-16.json:
[{"title":"De Monitor","title_link":"http://demonitor.ncrv.nl/"}]
然后我创建一个数据框
test_path <- "data"
test_files <- list.files(test_path, pattern = "*.json")
test_files %>%
map_df(~fromJSON(file.path(test_path, .), flatten = TRUE))
期望的输出:
title title_link file_name
1 Moral Machine http://moralmachine.mit.edu/ 2020-06-15.json
2 De Monitor http://demonitor.ncrv.nl/ 2020-06-16.json
【问题讨论】:
-
任何 json 文件是否只包含一个观察结果?