I have some json data [{a:10, b:123,c:4.5},{a:2,b:5,c:33}] and so on that I read into R via json_data <- fromJSON(paste(json_file, collapse="")) (json_file is the input url). So far so fine.
Now I would like to create vectors from this input which fromJSON has converted into a List of vectors where the vectors have components a,b,c.
Is there a better way than looping over the input list and doing this manually by concatenating the individual vector components on the new target vector(s)?
If you have a list like this:
You could just do something like the following:
(The
do.call(rbind, X)construct is handy, allowing you torbindtogether the elements of a list of arbitrary length. You can then slice and dice the resulting matrix as you see fit — I just converted it to adata.frameand then to alistto show a couple of possibilities.)