ajschumacher / rjstat

read and write JSON-stat with R
Other
31 stars 6 forks source link

Ordering of data when using rjstat and ONS API #10

Closed jodyaberdein closed 8 years ago

jodyaberdein commented 8 years ago

It has been suggested over on stackoverflow that I post here regarding an issue with rjstat and the UK ONS API. This may of course be my complete inability to code correctly, but please see the comments linked below:

https://stackoverflow.com/questions/33420105/how-can-i-preserve-recreate-correct-order-in-json-stat-data-imported-to-r-from

ajschumacher commented 8 years ago

Your SO question is not replicable because it relies on your API key, which is masked.

My guess is that you're hiding too much of what's there in the final line you give:

ONS_JSON$`Usual resident population`[1:10,c('2011 Westminster Parliamentary Constituency Hierarchy','value')]

What are the other columns in the data frame?

I don't think there is a problem related to order. It is not really true to say that JSON data is not ordered, and certainly arrays in JSON maintain order very nicely.

Does that help?

jodyaberdein commented 8 years ago

Wow that was quick.

Not sure what to do about the API key. Little harm in you having it I guess (jodyaberdein at doctors.net.uk

The whole data frame has columns:

[1] "2011 Westminster Parliamentary Constituency Hierarchy" [2] "Sex"
[3] "Measures"
[4] "Time"
[5] "value"

When you just view

ONS_JSON$Usual resident population

The population values are not matched to the correct areas, at least using the code I wrote to query the API.

Sorry if this is novice and not really an issue by the way. Happy to go play some more without bothering others.

hmalmedal commented 8 years ago

I registered for an API key and tried your example. I got

   2011 Westminster Parliamentary Constituency Hierarchy    value
1                                      England and Wales 56075912
2                                      England and Wales 27573376
3                                      England and Wales 28502536
4                                                England 53012456
5                                                England 26069148
6                                                England 26943308
7                                                  Wales  3063456
8                                                  Wales  1504228
9                                                  Wales  1559228
10                                            North East  2596886

I suspect that you have an old version of rjstat. The current version is 0.2.1.

jodyaberdein commented 8 years ago

That's great. I'll give it a go with new rjstat

jodyaberdein commented 8 years ago

Yep that's got it, thanks!

ajschumacher commented 8 years ago

@hmalmedal saves the day again! :+1: :+1: :+1: :smile: