This R package provides tools to work with swedish identity numbers such as personal identity numbers (personnummer) and organizational identity numbers (organisationsnummer).
Installation (Installation)
Example: personal identity numbers (Personal identity numbers)
Example: organizational identity numbers (Organizational identity number)
Licensing and Citations (Licensing and Citations)
References (References)
Install the stable release version in R:
install.packages("sweidnumbr")
Test the installation by loading the library:
library(sweidnumbr)
We also recommend setting the UTF-8 encoding:
Sys.setlocale(locale="UTF-8")
As a first step we need to convert personal identity numbers (pin) to the same standard format used by the Swedish tax authority.
example_pin <- c("640823-3234", "6408233234", "19640823-3230") example_pin <- as.pin(example_pin) example_pin
The next step is to test if the vector is a pin
object. To do this we use the is.pin()
function.
is.pin(example_pin)
This only check the format of the pin. To check the pin using the control number we use pin_ctrl()
.
pin_ctrl(example_pin)
We can now use pin_birthplace()
and pin_sex()
. To get information on sex and birthplace.
pin_sex(example_pin) pin_birthplace(example_pin)
As the last step we can calculate the age based on the pin. We choose the date where we want to calculate the age. If date is not specified the current date is used.
pin_age(example_pin) pin_age(example_pin, date = "2000-01-01")
It is also possible to format the pin for presentation in different forms. (Note however that the output of format_pin
is just a character and no longer a pin
object):
format_pin(example_pin, "%Y-%m-%d-%N") format_pin(example_pin, "%P")
Sometimes we want some example pin
s. We can easily simulate pin
s using rpin()
:
rpin(3)
Handling of organizational identity numbers is done in a similar fashion. But organizational numbers are only allowed to have one format.
example_oin <- c("556000-4615", "232100-0156", "802002-4280") example_oin <- as.oin(example_oin) example_oin
We can test if the vector has a correct format in a similar way as for pin
.
is.oin(example_oin)
With a vector of oin
we can check if the organizational number is correct.
oin_ctrl(example_oin)
We can also check the type of organization.
oin_group(example_oin)
Sometimes we want some example oin
s. We can easily simulate oin
s using roin()
:
roin(3)
This work can be freely used, modified and distributed under the open license specified in the DESCRIPTION file.
Kindly cite the work as follows
citation("sweidnumbr")
This vignette was created with
sessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.