View source: R/set_region_codes.R
set_region_codes | R Documentation |
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.
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
)
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 |
|
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()
.
same form as input
set_region_codes_vct()
: Standardize region codes with prefixes. For internal use
set_region_codes_fct()
: Standardize region codes with prefixes. For internal use
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.