Pulling data using blsAPI





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to pull BLS data using the blsAPI but keep getting empty data sets. When I run the sample code provided from BLS it works fine but when I run the same code on different series ids I get nothing. I have included my code below:



# ENU04013105111150 = Wages
# CXUMENBOYSLB0101M = expenditures

payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
'startyear'=1999,'endyear'=2002)
response<-blsAPI(payload,3)
json<-fromJSON(response)
apiDF<-function(data){
df <- data.frame(year=character(),
period=character(),
periodName=character(),
value=character(),
stringsAsFactors=FALSE)

i <- 0
for(d in data){
i <- i + 1
df[i,] <- unlist(d)
}
return(df)
}

wages.df<-apiDF(json$Results$series[[1]]$data)
expend.df<-apiDF(json$Results$series[[2]]$data)

names(wages.df)[4]<-'wages'
names(expend.df)[4]<-'expend'

df<-merge(wages.df, expend.df)
df [1] year period periodName wages expend <0 rows> (or 0-length row.names)


I am trying to get data for wages and expenditures that I can then manipulate and plot.










share|improve this question































    0















    I am trying to pull BLS data using the blsAPI but keep getting empty data sets. When I run the sample code provided from BLS it works fine but when I run the same code on different series ids I get nothing. I have included my code below:



    # ENU04013105111150 = Wages
    # CXUMENBOYSLB0101M = expenditures

    payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
    'startyear'=1999,'endyear'=2002)
    response<-blsAPI(payload,3)
    json<-fromJSON(response)
    apiDF<-function(data){
    df <- data.frame(year=character(),
    period=character(),
    periodName=character(),
    value=character(),
    stringsAsFactors=FALSE)

    i <- 0
    for(d in data){
    i <- i + 1
    df[i,] <- unlist(d)
    }
    return(df)
    }

    wages.df<-apiDF(json$Results$series[[1]]$data)
    expend.df<-apiDF(json$Results$series[[2]]$data)

    names(wages.df)[4]<-'wages'
    names(expend.df)[4]<-'expend'

    df<-merge(wages.df, expend.df)
    df [1] year period periodName wages expend <0 rows> (or 0-length row.names)


    I am trying to get data for wages and expenditures that I can then manipulate and plot.










    share|improve this question



























      0












      0








      0








      I am trying to pull BLS data using the blsAPI but keep getting empty data sets. When I run the sample code provided from BLS it works fine but when I run the same code on different series ids I get nothing. I have included my code below:



      # ENU04013105111150 = Wages
      # CXUMENBOYSLB0101M = expenditures

      payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
      'startyear'=1999,'endyear'=2002)
      response<-blsAPI(payload,3)
      json<-fromJSON(response)
      apiDF<-function(data){
      df <- data.frame(year=character(),
      period=character(),
      periodName=character(),
      value=character(),
      stringsAsFactors=FALSE)

      i <- 0
      for(d in data){
      i <- i + 1
      df[i,] <- unlist(d)
      }
      return(df)
      }

      wages.df<-apiDF(json$Results$series[[1]]$data)
      expend.df<-apiDF(json$Results$series[[2]]$data)

      names(wages.df)[4]<-'wages'
      names(expend.df)[4]<-'expend'

      df<-merge(wages.df, expend.df)
      df [1] year period periodName wages expend <0 rows> (or 0-length row.names)


      I am trying to get data for wages and expenditures that I can then manipulate and plot.










      share|improve this question
















      I am trying to pull BLS data using the blsAPI but keep getting empty data sets. When I run the sample code provided from BLS it works fine but when I run the same code on different series ids I get nothing. I have included my code below:



      # ENU04013105111150 = Wages
      # CXUMENBOYSLB0101M = expenditures

      payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
      'startyear'=1999,'endyear'=2002)
      response<-blsAPI(payload,3)
      json<-fromJSON(response)
      apiDF<-function(data){
      df <- data.frame(year=character(),
      period=character(),
      periodName=character(),
      value=character(),
      stringsAsFactors=FALSE)

      i <- 0
      for(d in data){
      i <- i + 1
      df[i,] <- unlist(d)
      }
      return(df)
      }

      wages.df<-apiDF(json$Results$series[[1]]$data)
      expend.df<-apiDF(json$Results$series[[2]]$data)

      names(wages.df)[4]<-'wages'
      names(expend.df)[4]<-'expend'

      df<-merge(wages.df, expend.df)
      df [1] year period periodName wages expend <0 rows> (or 0-length row.names)


      I am trying to get data for wages and expenditures that I can then manipulate and plot.







      r json api






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 16:38









      AS Mackay

      2,00951121




      2,00951121










      asked Jan 3 at 15:41









      Jonathan RauhJonathan Rauh

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          There seem to be a couple of things going on here. To start with, you're passing a value of 3 to the api_version argument in your blsAPI function, but the only acceptable values are 1 and 2. Second, it appears that series ENU04013105111150 has no data for the years you requested. This is what I ran:



          > library(rjson)
          > library(blsAPI)
          >
          > payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
          + 'startyear'=1999,'endyear'=2002)
          > response<-blsAPI(payload, 2)
          > json<-fromJSON(response)
          > apiDF<-function(data){
          + df <- data.frame(year=character(),
          + period=character(),
          + periodName=character(),
          + value=character(),
          + stringsAsFactors=FALSE)
          +
          + i <- 0
          + for(d in data){
          + i <- i + 1
          + df[i,] <- unlist(d)
          + }
          + return(df)
          + }
          >
          > json$message
          [1] "No Data Available for Series ENU04013105111150 Year: 1999" "No Data Available for Series ENU04013105111150 Year: 2000"
          [3] "No Data Available for Series ENU04013105111150 Year: 2001" "No Data Available for Series ENU04013105111150 Year: 2002"
          >
          > wages.df<-apiDF(json$Results$series[[1]]$data)
          > expend.df<-apiDF(json$Results$series[[2]]$data)
          >
          > dim(wages.df)
          [1] 0 4
          > dim(expend.df)
          [1] 4 4


          Note that the expenditures read in correctly (because I changed api_version to 2), but there aren't any data for the other series in that time frame.






          share|improve this answer
























          • Awesome! Thanks for your help!

            – Jonathan Rauh
            Jan 4 at 16:09












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025472%2fpulling-data-using-blsapi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          There seem to be a couple of things going on here. To start with, you're passing a value of 3 to the api_version argument in your blsAPI function, but the only acceptable values are 1 and 2. Second, it appears that series ENU04013105111150 has no data for the years you requested. This is what I ran:



          > library(rjson)
          > library(blsAPI)
          >
          > payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
          + 'startyear'=1999,'endyear'=2002)
          > response<-blsAPI(payload, 2)
          > json<-fromJSON(response)
          > apiDF<-function(data){
          + df <- data.frame(year=character(),
          + period=character(),
          + periodName=character(),
          + value=character(),
          + stringsAsFactors=FALSE)
          +
          + i <- 0
          + for(d in data){
          + i <- i + 1
          + df[i,] <- unlist(d)
          + }
          + return(df)
          + }
          >
          > json$message
          [1] "No Data Available for Series ENU04013105111150 Year: 1999" "No Data Available for Series ENU04013105111150 Year: 2000"
          [3] "No Data Available for Series ENU04013105111150 Year: 2001" "No Data Available for Series ENU04013105111150 Year: 2002"
          >
          > wages.df<-apiDF(json$Results$series[[1]]$data)
          > expend.df<-apiDF(json$Results$series[[2]]$data)
          >
          > dim(wages.df)
          [1] 0 4
          > dim(expend.df)
          [1] 4 4


          Note that the expenditures read in correctly (because I changed api_version to 2), but there aren't any data for the other series in that time frame.






          share|improve this answer
























          • Awesome! Thanks for your help!

            – Jonathan Rauh
            Jan 4 at 16:09
















          0














          There seem to be a couple of things going on here. To start with, you're passing a value of 3 to the api_version argument in your blsAPI function, but the only acceptable values are 1 and 2. Second, it appears that series ENU04013105111150 has no data for the years you requested. This is what I ran:



          > library(rjson)
          > library(blsAPI)
          >
          > payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
          + 'startyear'=1999,'endyear'=2002)
          > response<-blsAPI(payload, 2)
          > json<-fromJSON(response)
          > apiDF<-function(data){
          + df <- data.frame(year=character(),
          + period=character(),
          + periodName=character(),
          + value=character(),
          + stringsAsFactors=FALSE)
          +
          + i <- 0
          + for(d in data){
          + i <- i + 1
          + df[i,] <- unlist(d)
          + }
          + return(df)
          + }
          >
          > json$message
          [1] "No Data Available for Series ENU04013105111150 Year: 1999" "No Data Available for Series ENU04013105111150 Year: 2000"
          [3] "No Data Available for Series ENU04013105111150 Year: 2001" "No Data Available for Series ENU04013105111150 Year: 2002"
          >
          > wages.df<-apiDF(json$Results$series[[1]]$data)
          > expend.df<-apiDF(json$Results$series[[2]]$data)
          >
          > dim(wages.df)
          [1] 0 4
          > dim(expend.df)
          [1] 4 4


          Note that the expenditures read in correctly (because I changed api_version to 2), but there aren't any data for the other series in that time frame.






          share|improve this answer
























          • Awesome! Thanks for your help!

            – Jonathan Rauh
            Jan 4 at 16:09














          0












          0








          0







          There seem to be a couple of things going on here. To start with, you're passing a value of 3 to the api_version argument in your blsAPI function, but the only acceptable values are 1 and 2. Second, it appears that series ENU04013105111150 has no data for the years you requested. This is what I ran:



          > library(rjson)
          > library(blsAPI)
          >
          > payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
          + 'startyear'=1999,'endyear'=2002)
          > response<-blsAPI(payload, 2)
          > json<-fromJSON(response)
          > apiDF<-function(data){
          + df <- data.frame(year=character(),
          + period=character(),
          + periodName=character(),
          + value=character(),
          + stringsAsFactors=FALSE)
          +
          + i <- 0
          + for(d in data){
          + i <- i + 1
          + df[i,] <- unlist(d)
          + }
          + return(df)
          + }
          >
          > json$message
          [1] "No Data Available for Series ENU04013105111150 Year: 1999" "No Data Available for Series ENU04013105111150 Year: 2000"
          [3] "No Data Available for Series ENU04013105111150 Year: 2001" "No Data Available for Series ENU04013105111150 Year: 2002"
          >
          > wages.df<-apiDF(json$Results$series[[1]]$data)
          > expend.df<-apiDF(json$Results$series[[2]]$data)
          >
          > dim(wages.df)
          [1] 0 4
          > dim(expend.df)
          [1] 4 4


          Note that the expenditures read in correctly (because I changed api_version to 2), but there aren't any data for the other series in that time frame.






          share|improve this answer













          There seem to be a couple of things going on here. To start with, you're passing a value of 3 to the api_version argument in your blsAPI function, but the only acceptable values are 1 and 2. Second, it appears that series ENU04013105111150 has no data for the years you requested. This is what I ran:



          > library(rjson)
          > library(blsAPI)
          >
          > payload<-list('seriesid'=c('ENU04013105111150','CXUMENBOYSLB0101M'),
          + 'startyear'=1999,'endyear'=2002)
          > response<-blsAPI(payload, 2)
          > json<-fromJSON(response)
          > apiDF<-function(data){
          + df <- data.frame(year=character(),
          + period=character(),
          + periodName=character(),
          + value=character(),
          + stringsAsFactors=FALSE)
          +
          + i <- 0
          + for(d in data){
          + i <- i + 1
          + df[i,] <- unlist(d)
          + }
          + return(df)
          + }
          >
          > json$message
          [1] "No Data Available for Series ENU04013105111150 Year: 1999" "No Data Available for Series ENU04013105111150 Year: 2000"
          [3] "No Data Available for Series ENU04013105111150 Year: 2001" "No Data Available for Series ENU04013105111150 Year: 2002"
          >
          > wages.df<-apiDF(json$Results$series[[1]]$data)
          > expend.df<-apiDF(json$Results$series[[2]]$data)
          >
          > dim(wages.df)
          [1] 0 4
          > dim(expend.df)
          [1] 4 4


          Note that the expenditures read in correctly (because I changed api_version to 2), but there aren't any data for the other series in that time frame.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 16:59









          Joseph Clark McIntyreJoseph Clark McIntyre

          939126




          939126













          • Awesome! Thanks for your help!

            – Jonathan Rauh
            Jan 4 at 16:09



















          • Awesome! Thanks for your help!

            – Jonathan Rauh
            Jan 4 at 16:09

















          Awesome! Thanks for your help!

          – Jonathan Rauh
          Jan 4 at 16:09





          Awesome! Thanks for your help!

          – Jonathan Rauh
          Jan 4 at 16:09




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025472%2fpulling-data-using-blsapi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          ts Property 'filter' does not exist on type '{}'

          mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window