Search code examples
rjson

How do I print particular JSON value in R?


install.packages("rjson")

library("rjson")

result <- fromJSON(file="provdata.json.txt")

for (i in seq(1,5,1))

{

  term <- result$data[i]

  print(term)

}

[output]

I was wondering what should I put to only print 13.6 and 4.15.


Solution

  • Your problem is that you're not subsetting the list deep enough: instead of the

    term <- result$data[i]
    
    print(term)
    

    bit, try with

    print(result$data[[1]][[1]][2])
    

    or something similar.