updated age_calc to also support cpr format ddmmyyxxxx 2022-08-24 14:37:30

This commit is contained in:
AG Damsbo 2022-08-24 14:37:30 +02:00
parent b5152b5e70
commit 3a0cd0d10a
4 changed files with 21 additions and 7 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,6 +1,6 @@
Package: daDoctoR Package: daDoctoR
Title: Functions For Health Research Title: Functions For Health Research
Version: 0.22.1 Version: 0.22.2
Year: 2021 Year: 2021
Author: Andreas Gammelgaard Damsbo <agdamsbo@pm.me> Author: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me> Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
@ -10,4 +10,4 @@ Suggest: shiny
License: GPL (>= 2) License: GPL (>= 2)
Encoding: UTF-8 Encoding: UTF-8
LazyData: true LazyData: true
RoxygenNote: 7.1.2 RoxygenNote: 7.2.1

View File

@ -12,9 +12,21 @@ dob_extract_cpr<-function(cpr)
## Input as cpr-numbers in format ddmmyy-xxxx ## Input as cpr-numbers in format ddmmyy-xxxx
## Build upon data from this document: https://cpr.dk/media/167692/personnummeret%20i%20cpr.pdf ## Build upon data from this document: https://cpr.dk/media/167692/personnummeret%20i%20cpr.pdf
## example vector: fsd<-c("010190-2000", "010115-4000", "010189-6000","010189-3000","010150-6000","010150-4000") ## 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)%in%c(0:9))){stop("Input format should be ddmmyy-xxxx")} # test if input is ddmmyyxxxx
else { if (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() dobs<-c()
a00<-as.numeric(c(0:99)) a00<-as.numeric(c(0:99))
@ -27,7 +39,9 @@ dob_extract_cpr<-function(cpr)
for (x in cpr) for (x in cpr)
{ {
p56<-as.numeric(substr(x,5,6)) p56<-as.numeric(substr(x,5,6))
p8<-as.numeric(substr(x,8,8))
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") birth<-as.Date(substr(x,1,6),format="%d%m%y")
@ -58,5 +72,5 @@ dob_extract_cpr<-function(cpr)
} }
return(dobs) return(dobs)
}
} }

View File

@ -12,7 +12,7 @@ devtools::document()
# Commit and push # Commit and push
commit_message<-"age_calc update to handle vector of enddates" commit_message<-"updated age_calc to also support cpr format ddmmyyxxxx"
library(git2r) library(git2r)
library(lubridate) library(lubridate)