我有一个JSON文件。虽然原始文件很大,但为了回答这个问题,我将其简化为一个小得多的可重现示例(无论大小,我仍然会得到相同的错误):
{
"relationships_followers": [
{
"title": "",
"media_list_data": [
],
"string_list_data": [
{
"href": "https://www.instagram.com/testaccount1",
"value": "testaccount1",
"timestamp": 1669418204
}
]
},
{
"title": "",
"media_list_data": [
],
"string_list_data": [
{
"href": "https://www.instagram.com/testaccount2",
"value": "testaccount2",
"timestamp": 1660426426
}
]
},
{
"title": "",
"media_list_data": [
],
"string_list_data": [
{
"href": "https://www.instagram.com/testaccount3",
"value": "testaccount3",
"timestamp": 1648230499
}
]
},
{
"title": "",
"media_list_data": [
],
"string_list_data": [
{
"href": "https://www.instagram.com/testaccount4",
"value": "testaccount4",
"timestamp": 1379513403
}
]
}
]
}
我尝试将其转换为R中的 Dataframe ,其中包含href
、value
和timestamp
变量的值:
但是当我运行下面的代码时,我从另一个关于将JSON转换为R的SO答案中提取了这个代码:
library("rjson")
result <- fromJSON(file = "test_file.json")
json_data_frame <- as.data.frame(result)
我遇到了关于不同行的错误。
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 1, 0
如何将我的数据转换为所需的DF格式?
2条答案
按热度按时间hsvhsicv1#
数据似乎是嵌套的...
试试这个:
l5tcr1uw2#
这是因为存在嵌套数据。
注意:默认情况下,
jsonlite
包在解析data.frame方面做得更好。