SCB: Query the collection of SCB tables for data

Description Usage Arguments Details Value See Also Examples

View source: R/SCB.r

Description

This function is the main meat of the library, allowing you to query a large collection of statistical tables from Statistics Sweden (SCB) and other sources of official statistics. The syntax is very simple – you pass as parameters the names of columns that are present in a table (e.g. EducationLevel), and set them to values of that column you want (e.g. "Postgraduate education"), and then SCB(EducationLevel = "Postgraduate education") tells you how many people in Sweden have a postgraduate education (94718). Adding more parameters lets you narrow your query down further – SCB(EducationLevel = "Postgraduate education", Gender="Women") tells you how many of those are women (37906), and this can be even further narrowed down to SCB(EducationLevel = "Postgraduate education", Gender="Women", Municipality="Uppsala") if you want to know how many of those women live in Uppsala (3679).

Usage

1
2
3
4
5
6
7
SCB(
  verbose = FALSE,
  forceTable = NA_character_,
  failIfUnable = FALSE,
  collisionHandlingMode = "error",
  ...
)

Arguments

verbose

Should extra messages explaining what is going on be printed? If you are getting unexpected results, setting this to TRUE might make things clearer.

forceTable

Force the query to go to a specific table. Useful if your query could be answered by multiple tables, but you know which you want data from. See examples.

failIfUnable

Should an error be thrown if there is no table that can handle your query? The default, FALSE, only returns NA and gives a warning.

collisionHandlingMode

What should happen if more than one table can handle your query? There are four options: "error", the default, simply throws an error if this happens. "namedVector" queries all of the tables that can handle your query, and returns a vector of the results, with names of the table they came from. "consensus" tries the query against all tables that can handle it – if they all give the same answer, that is what is returned, otherwise, it throws an error. "arbitrary" arbitrarily chooses a table that can handle your query and returns what it says.

...

All the columns you want to specify. See the description.

Details

To be specific, when SCB(...) is called, it looks at the parameters it has been given, and checks if there is some table which has all the columns specified, and all of those columns have all the levels specified. If so, it looks at that table, subsets it to just the entries where all the given columns have one of the given values of that column, and then it sums the values in the "value column" of the rows in that subset. That is, all tables are pivoted to the longest possible form, so that all the actual data is stored in one column, which is the one we sum over – see the following vignette for more details on this concept: vignette("pivot", package="tidyr") (requires that you have tidyr installed.).

For a full list of the tables you can query, and what columns they have with what levels, see the "See also" section of this documentation.

There are a couple of named parameters, which don't query, but instead give some settings for how the query works, like how much output you expect and what to do if more than one table can handle your query. They also permit you to force your query to be sent to a specific table. See the "arguments" section.

Value

A numeric value. What this value represents can vary greatly by your specific query – it could be anything from an amount of people to a tax rate to an area of land.

See Also

The available tables are documented at: AgeGender, BirthRegion, EducationLevel, MunicipalIncomeStatements, HighSchoolEligibility, HouseholdSize, HousingForm, Incomes, LandUse, MaritalStatus, TaxRates.

Examples

1
2
3
4
5
# How many divorced 24-year-old women were there in Uppsala municipality in 2019?
SCB(Municipality = "Uppsala", Age=24, Gender="Women", MaritalStatus = "Divorced")
# 14
# How much forest was there in Lomma municipality in 2015?
SCB(Municipality = "Lomma", LandUseType = "Total forest")

vagdur/SCBHandlerPlotter documentation built on March 28, 2021, 11:35 p.m.