JSON data to dataframe in R -


i have json file importing data

mylist = rjson::fromjson(file = "jsdata.json") mylist   [[1]] [[1]]$key [1] "type1|new york, ny|nyc|hit" [[1]]$doc_count [1] 12  [[2]] [[2]]$key [2] "type1|omaha, ne|omaha|hit" [[2]]$doc_count [2] 8 

but when trying convert data frame function below ,
do.call(rbind, lapply(mylist, data.frame))

i getting error.-
error in (function (..., row.names = null, check.rows = false, check.names = true, : arguments imply differing number of rows: 1, 0


i need parse data can used in excel csv. looked @ solution getting imported json data data frame in r
output not coming in proper usable format in excel.

and jsdata.json sample data looks this:

[{"key":"type1|new york, ny|nyc|hit","doc_count":12}, {"key":"type1|omaha, ne|omaha|hit","doc_count":8}, {"key":"type2|yuba city, ca|yuba|hit","doc_count":9}]

you can try :

require(jsonlite)  s  ='[{"key":"type1|new york, ny|nyc|hit","doc_count":12},        .......         "key":"type2|yuba city, ca|yuba|hit","doc_count":9}]'  df <- fromjson(s) df                               key doc_count  1   type1|new york, ny|nyc|hit        12  2    type1|omaha, ne|omaha|hit         8  3 type2|yuba city, ca|yuba|hit         9 

i don't know how want deal wiyh key .....


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -