0

I streamed a file with 120 JSON objects into R using jsonlite's stream_in().

R reports df$rules as a data frame but I cannot seem to be able to access "tag" using df$rules$tag not df$rules[,2].

Here's the structure of rules within df:

"rules":{"source":{"rule":"","tag":"tag_1"}}

PS: After writing the question I was able to format it into a data frame (using do.call & rbind.fill) but the question still holds as this is part of a larger data frame from which I want to apply some conditional scripts.

To reformat my question: how can subset the json data frame based on this "tag"?

Update: The above was solved by Jaap's suggest link.

Now I have another problem. I'm looping over many json objects, extracting the above lists and want each to be in the same data frame corresponding, obviously, to the same variable. Actually I am doing this for several lists arrays within the json objects. Here's an example (part of a json object).

Community
  • 1
  • 1
user10853
  • 302
  • 1
  • 4
  • 17
  • 1
    maybe you can find some inspiration [here](http://stackoverflow.com/questions/21121699/unable-to-convert-json-to-dataframe) – Jaap Aug 20 '15 at 08:08
  • Thanks @Jaap this helped. But I have another problem. I need th result (which is a list) to be included in a data frame. I'm looping over many json objects, extracting the above lists and want each to be in the same data frame corresponding, obviously, to the same variable. Any help with this? It's bugging my mind & its my first time dealing wiht json. – user10853 Aug 20 '15 at 10:16
  • Could you show us an example of such a list? – Jaap Aug 20 '15 at 10:20

1 Answers1

0

I don't think I fully understand the expected result, but perhaps this helps.

library(jsonlite)

sample_nlp <- fromJSON(
  "http://pastebin.com/raw.php?i=yik5Vif4",
  simplifyDataFrame = FALSE
)
# pretend like we have twenty by replicating the sample
nlp_array <- lapply(
  1:20,
  function(x){sample_nlp}
)

search_tags <- "Vyapam"
Filter(
  function(x){
    return(search_tags %in% unname(unlist(x$hashtags)))
  },
  nlp_array
)
timelyportfolio
  • 6,479
  • 30
  • 33