r - 如何将 JSON 转换为 DF?
问题描述
我正在使用 Rstudio 代码,我有 450 个 JSON 文件,我的工作区中都有,一些 JSON 文件都是正确的,但是有一些像这样的文件(https://drive.google.com/file/d /1DsezCmN8_8iLNCAsLZiRnxTrwnWu6LkD/view?usp=sharing,是 296kb json)当我尝试将字段 tm 设置为数据帧时,我遇到了这个错误
(function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : 参数暗示不同的行数: 0, 1
我使用的代码是
JSONList <- rjson::fromJSON(file = "2.json", simplify = F)
DF <- as.data.frame(JSONList$tm)
使用正常的文件,我获得了 5168 个变量的 1 个观察值。
我怎样才能避免一些文件的这个问题?
谢谢
解决方案
我认为另一种可能性是选择我需要的行
candidatos = list(
"name",
"score",
"tot_sFieldGoalsMade",
"tot_sFieldGoalsAttempted",
"tot_sTwoPointersMade",
"tot_sTwoPointersAttempted",
"tot_sThreePointersMade",
"tot_sThreePointersAttempted",
"tot_sFreeThrowsMade",
"tot_sFreeThrowsAttempted",
"tot_sReboundsDefensive",
"tot_sReboundsOffensive",
"tot_sReboundsTotal",
"tot_sAssists",
"tot_sBlocks",
"tot_sTurnovers",
"tot_sFoulsPersonal",
"tot_sPointsInThePaint",
"tot_sPointsSecondChance",
"tot_sPointsFromTurnovers",
"tot_sBenchPoints",
"tot_sPointsFastBreak",
"tot_sSteals"
)
ListColum<-map(candidatos, function(x){
as.data.frame(data$tm$"2"$x)
} )
但是 R 给了我一个没有元素的 23 个 DF 的列表
推荐阅读
- css - CSS 溢出:自动在 ios 和 safari 上搞砸了
- python - 使用scrapy提取h2标签下的所有文本
- mysql - 从联合表中一次获取一条记录
- python - Python 套接字突然收到不同的 fernet 密钥
- javascript - 去掉 gatsbyjs 中的链接下划线
- node.js - msg.content 未定义
- angular - Angular 9:间谍等待功能(单元测试)
- java - 在 String Java 中用全名替换所有特殊字符的最佳方法是什么?
- kubernetes - 如何在openshift中自动缩放spring批处理应用程序
- xml - 在 xslt 的逗号分隔列表中查找确切的单词