Facilitates working with Statistics Canada data table values retrieved using the package by setting all units to counts/dollars instead of millions, etc. If "replacement_value" is not set, it will replace the VALUE field with normalized values and drop the scale column. Otherwise it will keep the scale columns and create a new column named replacement_value with the normalized value. It will attempt to parse the REF_DATE field and create an R date variable. This is currently experimental.

normalize_cansim_values(data, replacement_value = NA,
  normalize_percent = TRUE, default_month = "01", default_day = "01",
  factors = FALSE, strip_classification_code = FALSE)

Arguments

data

A retrieved data table as returned from get_cansim() pr get_cansim_ndm()

replacement_value

(Optional) the name of the column the manipulated value should be returned in. Defaults to replacing the current value field

normalize_percent

(Optional) When true (the default) normalizes percentages by changing them to rates

default_month

The default month that should be used when creating Date objects for annual data (default set to "01")

default_day

The default day of the month that should be used when creating Date objects for monthly data (default set to "01")

factors

(Optional) Logical value indicating if dimensions should be converted to factors. (Default set to false).

strip_classification_code

(strip_classification_code) Logical value indicating if classification code should be stripped from names. (Default set to false).

Value

Returns the input tibble with with adjusted values

Examples

cansim_table <- get_cansim("34-10-0013")
#> Reading CANSIM NDM product 34-10-0013 from cache.
normalize_cansim_values(cansim_table)
#> # A tibble: 550 x 17 #> REF_DATE GEO DGUID `Type of proper… UOM UOM_ID VECTOR COORDINATE VALUE #> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> #> 1 2005 Cana… 2016… Residential Doll… 81 v6558… 1.1 2.34e12 #> 2 2005 Newf… 2016… Residential Doll… 81 v6558… 2.1 1.85e10 #> 3 2005 Prin… 2016… Residential Doll… 81 v6558… 3.1 4.33e 9 #> 4 2005 Nova… 2016… Residential Doll… 81 v6558… 4.1 4.43e10 #> 5 2005 New … 2016… Residential Doll… 81 v6558… 5.1 2.26e10 #> 6 2005 Queb… 2016… Residential Doll… 81 v6558… 6.1 4.05e11 #> 7 2005 Onta… 2016… Residential Doll… 81 v6558… 7.1 1.03e12 #> 8 2005 Mani… 2016… Residential Doll… 81 v6558… 8.1 4.93e10 #> 9 2005 Sask… 2016… Residential Doll… 81 v6558… 9.1 3.65e10 #> 10 2005 Albe… 2016… Residential Doll… 81 v6558… 10.1 2.44e11 #> # … with 540 more rows, and 8 more variables: STATUS <chr>, SYMBOL <chr>, #> # TERMINATED <chr>, DECIMALS <chr>, GeoUID <chr>, `Classification Code for #> # Type of property` <chr>, `Hierarchy for Type of property` <chr>, #> # Date <date>