Title: | Directly Extracts Complete CANSIM Data Tables |
---|---|
Description: | Extract CANSIM (Statistics Canada) tables and transform them into readily usable data in panel (wide) format. It can also extract more than one table at a time and produce the resulting merge by time period and geographical region. |
Authors: | Marco Lugo <[email protected]> |
Maintainer: | Marco Lugo <[email protected]> |
License: | GPL-3 |
Version: | 1.14.1 |
Built: | 2024-10-31 06:42:18 UTC |
Source: | CRAN |
Extracts a complete CANSIM (Statistics Canada) data table and converts it into a readily usable panel (wide) format.
getCANSIM(cansimTableNumber='', showLabels = TRUE, raw = FALSE, lang = 'eng')
getCANSIM(cansimTableNumber='', showLabels = TRUE, raw = FALSE, lang = 'eng')
cansimTableNumber |
- the table number we wish to retrieve from CANSIM. |
showLabels |
- show the Statistics Canada labels after finishing extracting and converting the table, TRUE by default. |
raw |
- download the CANSIM table as-is, skipping all processing, FALSE by default. |
lang |
- language for data labels ('eng' for English or 'fra' for French), 'eng' by default. |
Geographic variables are renamed i, time variables are renamed t, and all the other variables are renamed with a generic V1, V2, ..., Vn. The generic variables keep the full Statistics Canada description by using a label.
data frame containing CANSIM table.
getCANSIM("12-10-0005") getCANSIM("12-10-0005", lang = 'fra')
getCANSIM("12-10-0005") getCANSIM("12-10-0005", lang = 'fra')
Extracts more than one CANSIM table and produces a merged table (by ID and period).
mergeCANSIM(cansimTableVector, keepUnmatched = FALSE, showLabels = TRUE, lang = 'eng')
mergeCANSIM(cansimTableVector, keepUnmatched = FALSE, showLabels = TRUE, lang = 'eng')
cansimTableVector |
- vector containing all the CANSIM tables to extract and merge. |
keepUnmatched |
- if true, keeps all values, even if no match was found. FALSE by default. |
showLabels |
- show the Statistics Canada labels after finishing extracting and converting the table, TRUE by default. |
lang |
- language for data labels ('eng' for English or 'fra' for French), 'eng' by default. |
data frame containing CANSIM tables.
mergeCANSIM( c(23100067, 23100238) )
mergeCANSIM( c(23100067, 23100238) )
Helper function to search through the Hmisc labels in order to obtain the variable name mapping to their respective labels. It can be particularly useful for bigger datasets for which manual exploration and visualization can be prohibitive.
searchLabels(df, pattern)
searchLabels(df, pattern)
df |
- data.frame obtained using the getCANSIM function. |
pattern |
- the string to search for in the variable labels. |
Search is case insensitive.
df <- getCANSIM("12-10-0005") searchLabels(df, "imports")
df <- getCANSIM("12-10-0005") searchLabels(df, "imports")