Quandl - Converting JSON data into data frame uisng R

169 views Asked by At

I am trying to pull data from quandl website. I am using jsonlite library of R to pull the data. It's working fine. But, when I converting it to dataframe, it's throwing me following error

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
arguments imply differing number of rows: 1, 9, 0, 14484

I am using below code to pull the data and convert it to data frame so that I can export the data using R.

library(jsonlite)
url = "https://www.quandl.com/api/v3/datasets/CHRIS/CME_S1.json"
data=jsonlite::fromJSON(url, simplifyDataFrame = TRUE)
data = plyr::ldply(data, rbind)

The data type is list :

str(data)
List of 1
$ dataset:List of 21
..$ id                   : int 10922651
..$ dataset_code         : chr "CME_S1"
..$ database_code        : chr "CHRIS"
..$ name                 : chr "Soybean Futures, Continuous Contract #1 (S1) (Front Month)"
..$ description          : chr "Historical Futures Prices: Soybean Futures, Continuous Contract #1. Non-adjusted price based on spot-month continuous contract "| __truncated__
..$ refreshed_at         : chr "2017-01-04T07:29:55.688Z"
..$ newest_available_date: chr "2017-01-03"
..$ oldest_available_date: chr "1959-07-01"
..$ column_names         : chr [1:9] "Date" "Open" "High" "Low" ...
..$ frequency            : chr "daily"
..$ type                 : chr "Time Series"
..$ premium              : logi FALSE
..$ limit                : NULL
..$ transform            : NULL
..$ column_index         : NULL
..$ start_date           : chr "1959-07-01"
..$ end_date             : chr "2017-01-03"
..$ data                 : chr [1:14484, 1:9] "2017-01-03" "2016-12-30" "2016-12-29" "2016-12-28" ...
..$ collapse             : NULL
..$ order                : NULL
..$ database_id          : int 596

I can see that, this error is because the imported data is in the list format. Is there a way to convert it to data frame so that I can export it in any format? I tried different ways but did get success. I would appreciate any kind of help.

0

There are 0 answers