How can I convert a quite complicated nested lists with data frames inside to one consolidated data frame?
Here are first 3 records in my raw input in JSON.
{
"abc": [[{"variant": "enabled", "allocation": 100}], [{"variant": "control", "allocation": 100}]],
"def": [[{"variant": "enable", "allocation": 100}]],
"hahaha": [[{"variant": "superman", "allocation": 5}, {"variant": "superhero", "allocation": 95}]]
}
Then I loaded this JSON file into R.
library(jsonlite)
myList <- fromJSON("myjsonfile.json")
str(myList)
List of 8988
$ abc :List of 2
..$ :'data.frame': 1 obs. of 2 variables:
.. ..$ variant : chr "enabled"
.. ..$ allocation: int 100
..$ :'data.frame': 1 obs. of 2 variables:
.. ..$ variant : chr "control"
.. ..$ allocation: int 100
$ def :List of 1
..$ :'data.frame': 1 obs. of 2 variables:
.. ..$ variant : chr "enable"
.. ..$ allocation: int 100
$ hahaha :List of 1
..$ :'data.frame': 2 obs. of 2 variables:
.. ..$ variant : chr [1:2] "superman" "superhero"
.. ..$ allocation: int [1:2] 5 95
As you can see in each list, there could be different number of data frames and each data frame may contain different number of obs.
Ideally I want to get one dataframe as below:
test_name, segments, variant, allocation
abc, 1, enabled, 100
abc, 2, control, 100
def, 1, enable, 100,
hahaha, 1, superman, 5
hahaha, 1, superhero, 95
What is a scalable approach for all 8988 records here? Appreciate your helps here.
dput?