mirror of
https://github.com/agdamsbo/daDoctoR.git
synced 2024-11-24 04:31:54 +01:00
Compare commits
No commits in common. "3b01487a0e31e06b60d0414387dfb1ca405f1294" and "9b81c4b34a4b7ddedc9df976e9140d3534e84d74" have entirely different histories.
3b01487a0e
...
9b81c4b34a
@ -1,6 +1,6 @@
|
||||
Package: daDoctoR
|
||||
Title: Functions For Health Research
|
||||
Version: 0.22.6
|
||||
Version: 0.22.4
|
||||
Year: 2021
|
||||
Author: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
||||
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
||||
|
@ -1,23 +1,14 @@
|
||||
#' CPR check
|
||||
#'
|
||||
#' Checking validity of cpr number
|
||||
#' @param cpr cpr-numbers as ddmmyy[-.]xxxx or ddmmyyxxxx. Also mixed formatting.
|
||||
#' @param x cpr as "ddmmyy-xxxx".
|
||||
#' @keywords cpr
|
||||
#' @export
|
||||
#' @examples
|
||||
#' cpr_check("231045-0637")
|
||||
|
||||
cpr_check<-function(cpr){
|
||||
# Check validity of CPR number, format ddmmyy-xxxx
|
||||
# Build upon data from this document: https://cpr.dk/media/167692/personnummeret%20i%20cpr.pdf
|
||||
# example vector: fsd<-c("2310450637", "010115-4000", "0101896000","010189-3000","300450-1030","010150-4021")
|
||||
|
||||
v <- c()
|
||||
|
||||
for (x in cpr){
|
||||
if (!substr(x,7,7)%in%c("-",".")){ # Added check to take p8 if ddmmyy[-.]xxxx,
|
||||
x<-paste(substr(x,1,6),substr(x,7,10),collapse="-")
|
||||
}
|
||||
cpr_check<-function(x){
|
||||
#Check validity of CPR number, format ddmmyy-xxxx
|
||||
|
||||
p1<-as.integer(substr(x,1,1))
|
||||
p2<-as.integer(substr(x,2,2))
|
||||
@ -30,10 +21,6 @@ cpr_check<-function(cpr){
|
||||
p9<-as.integer(substr(x,10,10))
|
||||
p10<-as.integer(substr(x,11,11))
|
||||
|
||||
v<-c(v,
|
||||
ifelse((p1*4+p2*3+p3*2+p4*7+p5*6+p6*5+p7*4+p8*3+p9*2+p10) %% 11 == 0,"valid","invalid")
|
||||
)
|
||||
}
|
||||
|
||||
return(v)
|
||||
result<-ifelse((p1*4+p2*3+p3*2+p4*7+p5*6+p6*5+p7*4+p8*3+p9*2+p10) %% 11 == 0,"valid","invalid")
|
||||
return(result)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#' Extracting date of birth from CPR
|
||||
#'
|
||||
#' For easy calculation.
|
||||
#' @param cpr cpr-numbers as ddmmyy[-.]xxxx or ddmmyyxxxx. Also mixed formatting.
|
||||
#' @param cpr cpr-numbers in format ddmmyy-xxxx.
|
||||
#' @keywords cpr
|
||||
#' @export
|
||||
#' @examples
|
||||
@ -11,11 +11,22 @@
|
||||
dob_extract_cpr<-function(cpr)
|
||||
## Input as cpr-numbers in format ddmmyy-xxxx
|
||||
## Build upon data from this document: https://cpr.dk/media/167692/personnummeret%20i%20cpr.pdf
|
||||
## example vector: fsd<-c("010190-2000", "010115-4000", "0101896000","010189-3000","300450-1030","010150-4021")
|
||||
## example vector: fsd<-c("010190-2000", "010115-4000", "010189-6000","010189-3000","010150-6000","010150-4000")
|
||||
## cpr <- "231045-0637"
|
||||
## cpr <- "2310450637"
|
||||
{
|
||||
|
||||
if (any(substr(cpr,7,7)=="-")){ # test if input is ddmmyy-xxxx, standard format
|
||||
message("Input er i formatet ddmmyy-xxxx")
|
||||
cpr_std<-TRUE
|
||||
}
|
||||
|
||||
if (any(substr(cpr,7,7)%in%c(0:9))){
|
||||
message("Input er i formatet ddmmyyxxxx") # test if input is ddmmyyxxxx
|
||||
cpr_std<-FALSE
|
||||
}
|
||||
|
||||
|
||||
dobs<-c()
|
||||
|
||||
a00<-as.numeric(c(0:99))
|
||||
@ -29,9 +40,7 @@ dob_extract_cpr<-function(cpr)
|
||||
{
|
||||
p56<-as.numeric(substr(x,5,6))
|
||||
|
||||
if (substr(x,7,7)%in%c("-",".")){
|
||||
p8<-as.numeric(substr(x,8,8)) # Added check to take p8 if ddmmyy[-.]xxxx,
|
||||
} else {p8<-as.numeric(substr(x,7,7))} # or p7 if ddmmyyxxxx
|
||||
if (cpr_std){p8<-as.numeric(substr(x,8,8))} else {p8<-as.numeric(substr(x,9,9))}
|
||||
|
||||
birth<-as.Date(substr(x,1,6),format="%d%m%y")
|
||||
|
||||
|
@ -4,10 +4,10 @@
|
||||
\alias{cpr_check}
|
||||
\title{CPR check}
|
||||
\usage{
|
||||
cpr_check(cpr)
|
||||
cpr_check(x)
|
||||
}
|
||||
\arguments{
|
||||
\item{cpr}{cpr-numbers as ddmmyy[-.]xxxx or ddmmyyxxxx. Also mixed formatting.}
|
||||
\item{x}{cpr as "ddmmyy-xxxx".}
|
||||
}
|
||||
\description{
|
||||
Checking validity of cpr number
|
||||
|
@ -7,7 +7,7 @@
|
||||
dob_extract_cpr(cpr)
|
||||
}
|
||||
\arguments{
|
||||
\item{cpr}{cpr-numbers as ddmmyy[-.]xxxx or ddmmyyxxxx. Also mixed formatting.}
|
||||
\item{cpr}{cpr-numbers in format ddmmyy-xxxx.}
|
||||
}
|
||||
\description{
|
||||
For easy calculation.
|
||||
|
Loading…
Reference in New Issue
Block a user