[英]How to split column into rows by Object in array?
大家好,我的 dataframe 看起来有点像这样:
**| Descriptor |**
[{"name": "Some name", "id": "L73871287"}, {"name": "Another name", "id": "L7123287"}]
[{"name": "Yet another name", "id": "L73556287"}, {"name": "Yet another name", "id": "L73556287"}]
go 如何按 R 中的对象拆分此数据? 所以要得到:
**| Descriptor |**
{"name": "Some name", "id": "L73871287"}
{"name": "Another name", "id": "L7123287"}
{"name": "Yet another name", "id": "L73556287"}
{"name": "Yet another name", "id": "L73556287"}
更好的是只得到一个列“名称”和一个列“id”,但是如果在 R 中可能的话,idk (我有一个 python 和 javascript 背景,但是对于 python 文件来说太大了)
也许这就是你正在寻找的:
library(jsonlite)
json <- '[{"name": "Some name", "id": "L73871287"}, {"name": "Another name", "id": "L7123287"}],
[{"name": "Yet another name", "id": "L73556287"}, {"name": "Yet another name", "id": "L73556287"}]'
ls <- fromJSON(txt = paste0("[", json, "]"))
do.call(rbind, ls)
#> name id
#> 1 Some name L73871287
#> 2 Another name L7123287
#> 3 Yet another name L73556287
#> 4 Yet another name L73556287
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.