A brief introduction to the r-package PxWebApiData is given below. Three calls to the main function, ApiData, is demonstrated. First, two calls for reading data sets are shown. The last call captures meta data. However, in practise, one may look at the meta data first. At the end, some background is given.
The dataset below has three variables, Region, ContentsCode and Tid. The variables can be used as input parameters. Here two of the parameters are specified by variable id’s and one parameter is specified by indices. Negative values are used to specify reversed indices. Thus, we here obtain the two first and the two last years in the data.
A list of two data frames is returned; the label version and the id version.
ApiData("http://data.ssb.no/api/v0/en/table/04861",
Region = c("0811", "0301"), ContentsCode = "Bosatte", Tid = c(1, 2, -2, -1))
$`04861: Area and population of urban settlements, by region, contents and year`
region contents year value
1 Oslo municipality Number of residents 2000 504348
2 Oslo municipality Number of residents 2002 508134
3 Oslo municipality Number of residents 2017 661732
4 Oslo municipality Number of residents 2018 668752
5 Siljan Number of residents 2000 1017
6 Siljan Number of residents 2002 1040
7 Siljan Number of residents 2017 1344
8 Siljan Number of residents 2018 1188
$dataset
Region ContentsCode Tid value
1 0301 Bosatte 2000 504348
2 0301 Bosatte 2002 508134
3 0301 Bosatte 2017 661732
4 0301 Bosatte 2018 668752
5 0811 Bosatte 2000 1017
6 0811 Bosatte 2002 1040
7 0811 Bosatte 2017 1344
8 0811 Bosatte 2018 1188
All possible values is obtained by TRUE and corresponds to “all” in the api query. Elimination of a variables is obtained by FALSE. An imaginary value corresponds to “top” in the api query.
$`04861: Area and population of urban settlements, by contents and year`
contents year value
1 Area of urban settlements (km²) 2016 2172.50
2 Area of urban settlements (km²) 2017 2191.30
3 Area of urban settlements (km²) 2018 2205.07
4 Number of residents 2016 4229827.00
5 Number of residents 2017 4283166.00
6 Number of residents 2018 4327937.00
$dataset
ContentsCode Tid value
1 Areal 2016 2172.50
2 Areal 2017 2191.30
3 Areal 2018 2205.07
4 Bosatte 2016 4229827.00
5 Bosatte 2017 4283166.00
6 Bosatte 2018 4327937.00
Meta information about the data set can be obtained by “returnMetaFrames = TRUE”.
$Region
values valueTexts
1 0101 Halden
2 0102 Sarpsborg (-1991)
3 0103 Fredrikstad (-1993)
4 0104 Moss
5 0105 Sarpsborg
6 0106 Fredrikstad
7 0111 Hvaler
8 0113 Borge (-1993)
9 0114 Varteig (-1991)
10 0115 Skjeberg (-1991)
11 0116 Berg (-1966)
12 0117 Idd (-1966)
13 0118 Aremark
14 0119 Marker
15 0121 Rømskog
16 0122 Trøgstad
17 0123 Spydeberg
18 0124 Askim
19 0125 Eidsberg
20 0127 Skiptvet
21 0128 Rakkestad
22 0130 Tune (-1991)
23 0131 Rolvsøy (1911-1993)
24 0133 Kråkerøy (1908-1993)
25 0134 Onsøy (-1993)
[ reached 'max' / getOption("max.print") -- omitted 552 rows ]
$ContentsCode
values valueTexts
1 Areal Area of urban settlements (km²)
2 Bosatte Number of residents
$Tid
values valueTexts
1 2000 2000
2 2002 2002
3 2003 2003
4 2004 2004
5 2005 2005
6 2006 2006
7 2007 2007
8 2008 2008
9 2009 2009
10 2011 2011
11 2012 2012
12 2013 2013
13 2014 2014
14 2015 2015
15 2016 2016
16 2017 2017
17 2018 2018
attr(,"text")
Region ContentsCode Tid
"region" "contents" "year"
attr(,"elimination")
Region ContentsCode Tid
TRUE FALSE FALSE
attr(,"time")
Region ContentsCode Tid
FALSE FALSE TRUE
PxWeb and it’s API, PxWebApi is used as output database (Statbank) by many statistical agencies in the Nordic countries and several others, i.e. Statistics Norway, Statistics Finland, Statistics Sweden. See list of installations: https://www.scb.se/en/services/statistical-programs-for-px-files/px-web/pxweb-examples/