0

I am getting data from BLS website using the package blsAPI.

The code is:

library(blsAPI)
employ <- blsAPI(payload= "CES0500000001")
emp <- fromJSON(employ)

The data set emp is a list... this is where I am stumped. I've been trying all types of variations to convert emp to data.frame from list with no success.

Artem
  • 3,304
  • 3
  • 18
  • 41
Manuel
  • 21
  • 2
  • 1
    Welcome to Stack Overflow! Please take the [tour] and read [ask]. Concerning your question, you have to provide a [mcve], so that anyone can reproduce your issue and, more importantly, to make sure the question doesn't contain anything irrelevant. – Ulrich Eckhardt Sep 17 '18 at 07:48
  • Possible duplicate of [R - list to data frame](https://stackoverflow.com/questions/4227223/r-list-to-data-frame) – divibisan Sep 17 '18 at 16:53
  • The answers to this question will tell you how to convert from a list to a data.frame. If they don't answer your question, please edit your question to show exactly what your data looks like, what you're trying to make it look like, and why those solutions don't work. – divibisan Sep 17 '18 at 16:55
  • In fact, @Manual provided minumum reproducible example. – Artem Sep 19 '18 at 21:23

1 Answers1

0

Just set the argument return_data_frame = TRUE of blsAPI function. data.frame will be returned instead of list (default behaviour).

library(rjson)
library(blsAPI)
response <- blsAPI("CES0500000001", return_data_frame = TRUE)
head(response)

Output:

  year period periodName  value      seriesID
1 2018    M08     August 126939 CES0500000001
2 2018    M07       July 126735 CES0500000001
3 2018    M06       June 126582 CES0500000001
4 2018    M05        May 126390 CES0500000001
5 2018    M04      April 126130 CES0500000001
6 2018    M03      March 125956 CES0500000001
Artem
  • 3,304
  • 3
  • 18
  • 41