[R] Convert json data to an r dataframe

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Dec 28 09:52:47 CET 2012


It really seems to me that what you ought to be doing is carefully studying the code provided at the lamages link that you referenced until you can modify it to do what you want. It really isn't fair for you to ask people to do your thinking for you. This is the R-help mailing list, not R-do-my-work-for-me mailing list.

JSON, like XML, is a far more flexible data format than a data frame. That means it is up to you to decide what data or relationships you want to ignore so you can squeeze some useful subset of the information into a data frame. There is no way to write a do-it-all function that does this for all cases. Your goals must be part of each extraction function you use, so you really need to write it yourself.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

"sp.duccio" <sp.duccio at gmail.com> wrote:

>Thank you very much, Rui!
>
>The problem with your script is that data is now in a string format,
>while
>I need to obtain a data.frame instead.
>Do you really think that I cannot do anything else with this json data?
>Thank you very much again
>
>Duccio
>
>
>2012/12/27 Rui Barradas <ruipbarradas at sapo.pt>
>
>>  Hello,
>>
>> Your dataset is not in tabular form, so I find it difficult to
>transform
>> it into a data.frame, but you can see it in R with the following.
>>
>>
>> install.packages("RJSONIO", dependencies = TRUE)
>> library(RJSONIO)
>>
>> url <-
>>
>"http://apistat.istat.it/?q=getdatajson&dataset=DCIS_POPSTRBIL&dim=1,0,0,0&lang=1&tr=&te="<http://apistat.istat.it/?q=getdatajson&dataset=DCIS_POPSTRBIL&dim=1,0,0,0&lang=1&tr=&te=>
>> dat <- fromJSON(url)
>>
>> str(dat)  # List with 3 components
>>
>> str(dat[[1]][[1]])
>> dat[[1]][[1]]
>>
>> str(dat[[1]][[2]])
>> unlist(dat[[1]][[2]])
>>
>> str(dat[[1]][[3]])
>> dat[[1]][[3]]
>>
>>
>> Hope this helps,
>>
>> Rui Barradas
>> Em 27-12-2012 11:55, sp.duccio escreveu:
>>
>> Hello to everybody,
>>
>> I need to convert a json dataset in an R dataframe.
>> I suppose that I'd need to use rjson or rjsonio package.
>> The json dataset
>is:http://apistat.istat.it/?q=getdatajson&dataset=DCIS_POPSTRBIL&dim=1,0,0,0&lang=1&tr=&te=
>> It would be nice if someone can help me to create a function like the
>one
>>
>below:http://lamages.blogspot.it/2011/09/accessing-and-plotting-world-bank-data.html
>> that can applied to my json dataset and with all the parameter values
>that
>> can be specifiable.
>> Is there anyone who can solve this problem?
>>
>> Thanx in advance for any help!
>> Duccio
>>
>>
>>
>>
>> ______________________________________________R-help at r-project.org
>mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>




More information about the R-help mailing list