Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use aggregation in Query #181

Open
larpSTATGL opened this issue Jul 17, 2019 · 1 comment
Open

Use aggregation in Query #181

larpSTATGL opened this issue Jul 17, 2019 · 1 comment
Milestone

Comments

@larpSTATGL
Copy link

larpSTATGL commented Jul 17, 2019

In a pxweb based statbank system defined aggregations can be used in a JSON query. You can locate relevant aggregations on your chosen site, by looking to "About table" - "API query for this table" after viewing a table on screen with selected aggregation

First the standard way - notice "*" (all) for age:

From the Greenlandic Statbank this query extract the female, greenlandic born population on 1-year age groups:

px_data_female <-
pxweb_get(url = "http://bank.stat.gl/api/v1/en/Greenland/BE/BE01/BE0120/BEXST1.PX",
query = list("age"=c(""),
"gender"=c("2"),
"place of birth"=c("N"),
"time"=c("
")))

NEXT use and compare agg-file and you get the aggregation in return:

if(!require(pxweb)){install.packages("pxweb")}
library(pxweb)

q_f <- '{"query": [{"code": "age","selection": {"filter": "agg:5-year.agg", "values": ["-4","5-9","10-14","15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59","60-64","65-69","70-74","75-79","80-84","85-89","90-94","95+"]}},{"code": "place of birth","selection": {"filter": "item","values": ["N"]}},{"code": "gender","selection": {"filter": "item","values": ["2"]}},{"code": "time","selection": {"filter": "all","values": ["*"]}}],"response": {"format": "px"}}'
px_data_female <-

pxweb_get(url = "http://bank.stat.gl/api/v1/en/Greenland/BE/BE01/BE0120/BEXST1.PX",
query = q_f)

px_data_female <- as.data.frame(px_data_female, column.name.type = "text", variable.value.type = "code")

matrix_female <- matrix(data = px_data_female$Population January 1st, ncol = 43, byrow = TRUE )

@MansMeg
Copy link
Contributor

MansMeg commented Jul 17, 2019

Thanks! Ill put this in the vignette later on.

@MansMeg MansMeg added this to the v. 1.0 milestone May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants