Skip to contents

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)

Arguments

pin

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

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.

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

# Examples taken from SKV 704 (see references)
ex_pin1 <- c("196408233234", "640823-3234", "19640823-3234")
as.pin(pin = ex_pin1)
#> [1] "196408233234" "196408233234" "196408233234"
#> Personal identity number(s)
ex_pin2 <- c("6408233234")
as.pin(ex_pin2)
#> Assumption: Pin of format YYMMDDNNNC is assumed to be less than 100 years old
#> [1] "196408233234"
#> Personal identity number(s)
ex_pin3 <- c(6408233234, 196408233234)
as.pin(ex_pin3)
#> Assumption: Pin of format YYMMDDNNNC is assumed to be less than 100 years old
#> [1] "196408233234" "196408233234"
#> Personal identity number(s)
ex_pin4 <-rep(c("20121209-0122", "201212090122", "121209-0122", "1212090122"),250)
as.pin(ex_pin4)
#> Assumption: Pin of format YYMMDDNNNC is assumed to be less than 100 years old
#>    [1] "201212090122" "201212090122" "201212090122" "201212090122"
#>    [5] "201212090122" "201212090122" "201212090122" "201212090122"
#>    [9] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [13] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [17] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [21] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [25] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [29] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [33] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [37] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [41] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [45] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [49] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [53] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [57] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [61] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [65] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [69] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [73] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [77] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [81] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [85] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [89] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [93] "201212090122" "201212090122" "201212090122" "201212090122"
#>   [97] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [101] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [105] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [109] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [113] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [117] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [121] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [125] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [129] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [133] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [137] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [141] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [145] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [149] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [153] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [157] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [161] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [165] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [169] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [173] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [177] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [181] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [185] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [189] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [193] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [197] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [201] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [205] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [209] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [213] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [217] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [221] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [225] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [229] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [233] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [237] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [241] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [245] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [249] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [253] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [257] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [261] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [265] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [269] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [273] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [277] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [281] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [285] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [289] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [293] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [297] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [301] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [305] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [309] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [313] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [317] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [321] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [325] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [329] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [333] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [337] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [341] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [345] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [349] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [353] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [357] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [361] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [365] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [369] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [373] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [377] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [381] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [385] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [389] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [393] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [397] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [401] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [405] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [409] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [413] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [417] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [421] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [425] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [429] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [433] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [437] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [441] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [445] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [449] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [453] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [457] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [461] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [465] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [469] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [473] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [477] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [481] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [485] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [489] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [493] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [497] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [501] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [505] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [509] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [513] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [517] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [521] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [525] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [529] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [533] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [537] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [541] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [545] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [549] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [553] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [557] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [561] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [565] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [569] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [573] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [577] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [581] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [585] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [589] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [593] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [597] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [601] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [605] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [609] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [613] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [617] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [621] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [625] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [629] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [633] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [637] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [641] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [645] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [649] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [653] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [657] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [661] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [665] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [669] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [673] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [677] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [681] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [685] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [689] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [693] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [697] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [701] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [705] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [709] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [713] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [717] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [721] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [725] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [729] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [733] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [737] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [741] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [745] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [749] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [753] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [757] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [761] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [765] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [769] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [773] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [777] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [781] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [785] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [789] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [793] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [797] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [801] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [805] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [809] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [813] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [817] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [821] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [825] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [829] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [833] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [837] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [841] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [845] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [849] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [853] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [857] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [861] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [865] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [869] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [873] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [877] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [881] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [885] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [889] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [893] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [897] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [901] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [905] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [909] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [913] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [917] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [921] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [925] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [929] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [933] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [937] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [941] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [945] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [949] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [953] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [957] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [961] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [965] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [969] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [973] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [977] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [981] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [985] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [989] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [993] "201212090122" "201212090122" "201212090122" "201212090122"
#>  [997] "201212090122" "201212090122" "201212090122" "201212090122"
#> Personal identity number(s)
ex_pin5 <-c("205012090122", "186512090122", "121209-0122", "121209-012A")
as.pin(pin = ex_pin5)
#> Assumption: People with birth year before 1967 and character 'A', 'T' or 'X' instead of control number assumed deceased before 1967.
#> Warning: Erroneous pin(s) (set to NA).
#> [1] NA             "186512090122" "201212090122" "20121209012A"
#> Personal identity number(s)
pin <-c("201212090122", "201212090122", "121209-0122", "1212090122")

ex_pin <- rpin(3)
is.pin(ex_pin)
#> [1] TRUE

ex_pin_char <- as.character(ex_pin)
is.pin(ex_pin_char)
#> [1] FALSE