set_region_codes: Standardize region codes

View source: R/set_region_codes.R

set_region_codesR Documentation

Standardize region codes

Description

To avoid non-unique region codes, use the prefixed region codes. This function "standardizes" region codes in this format. Region codes already in this format are left as they are.

Usage

set_region_codes(
  x,
  region_level = NULL,
  year = NULL,
  offline = TRUE,
  use_char_length_info = NULL
)

set_region_codes_vct(
  x,
  region_level = NULL,
  year = NULL,
  offline = TRUE,
  use_char_length_info = NULL
)

set_region_codes_fct(
  x,
  region_level = NULL,
  year = NULL,
  offline = TRUE,
  use_char_length_info = FALSE
)

Arguments

x

character vector of region codes

region_level

character, optional region level of the input region codes

year

double, optional year of the classification used

offline

logical, whether works offline with package data. Defaults to TRUE.

use_char_length_info

TRUE or named vector, whether to use code character length information in determining their region level. Defaults to NULL.

Details

The function is strict in not making any assumptions in cases of ambiguous region codes. Some plain numbers may map to multiple region codes and in these cases the user can restrict the domain by giving a set of region levels to whose codes input vector codes are allowed to match.

If your vector contains ambiguous codes you may try breaking it into pieces where you know the unique region level of the codes in each piece and treat these pieces separately giving region level as an argument.

The function does not create region codes from scratch itself but, inputs are matched to the potential codes in the official classifications. These classifications are accessed using get_regionclassification(). Thus, only real region codes can be set. The matching of inputs into potential region codes occurs in match_region_codes_interal() and match_region_codes().

Value

same form as input

Functions

  • set_region_codes_vct(): Standardize region codes with prefixes. For internal use

  • set_region_codes_fct(): Standardize region codes with prefixes. For internal use

Examples


  v <- c("191", "047", "063")
  set_region_codes(v)
  v <- c("020", "047", "15")
  set_region_codes(v, use_char_length_info = TRUE)
  v <- c("005", "020", "047", "MK01", "MK02", "MK04")
  set_region_codes(v, region_level = "kunta")
  f <- factor(c("005", "020", "047", "MK01", "MK02", "MK04"))
  set_region_codes(f, region_level = c("kunta"))

  # If input is not recognized as region code, tries to reduce it to double
  # and infer region from this number. This is how following is possible:
  set_region_codes("alue045")

  # But it means also that this happens
  set_region_codes("R2D2")


pttry/statficlassifications documentation built on Jan. 17, 2024, 4:36 p.m.