sweidnumbr (version 1.5.0)

as.pin: Parse personal identity numbers to ABS format

Description

as.pin Converts personal identity numbers of different formats to standard (ABS) pin format YYYYMMDDNNNC where YYYYMMDD is the date of birth, NNN is the birth number and C is the control number. is.pin checks wether an R object is of class "pin".

Usage

as.pin(pin)

is.pin(pin)

Value

as.pin returns a vector of class "pin" (with additional classes "AsIs" and character) with swedish personal identity numbers with standard ABS format "YYYYMMDDNNNC". is.pin returns TRUE if pin is of class "pin", otherwise FALSE.

Arguments

pin

Vector with swedish personal identity numbers in character or numeric format. See details.

Details

as.pin converts different formats of swedish personal identity numbers to the standard ABS format. The formats that can be converted are:

  • numeric: YYYYMMDDNNNC

  • numeric: YYMMDDNNNC (assuming < 100 years of age)

  • character: "YYYYMMDDNNNC"

  • character: "YYMMDD-NNNC", "YYMMDD+NNNC"

  • character: "YYYYMMDD-NNNC"

  • character: "YYMMDDNNNC" (assuming < 100 years of age)

(where "C" can be substituted by characters "A", "T" or "X" if "YYYY" < 1967).

References

Examples

Run this code
# Examples taken from SKV 704 (see references)
ex_pin1 <- c("196408233234", "640823-3234", "19640823-3234")
as.pin(pin = ex_pin1)
ex_pin2 <- c("6408233234")
as.pin(ex_pin2)
ex_pin3 <- c(6408233234, 196408233234)
as.pin(ex_pin3)
ex_pin4 <-rep(c("20121209-0122", "201212090122", "121209-0122", "1212090122"),250)
as.pin(ex_pin4)
ex_pin5 <-c("205012090122", "186512090122", "121209-0122", "121209-012A")
as.pin(pin = ex_pin5)
pin <-c("201212090122", "201212090122", "121209-0122", "1212090122")

ex_pin <- rpin(3)
is.pin(ex_pin)

ex_pin_char <- as.character(ex_pin)
is.pin(ex_pin_char)

Run the code above in your browser using DataLab