{"id":17224286,"url":"https://github.com/ekstroem/dkcpr","last_synced_at":"2025-10-13T04:03:47.592Z","repository":{"id":90094032,"uuid":"159755540","full_name":"ekstroem/DKcpr","owner":"ekstroem","description":"Working with Danish CPR numbers in R","archived":false,"fork":false,"pushed_at":"2019-03-27T00:31:46.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T14:39:03.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ekstroem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-30T02:14:42.000Z","updated_at":"2019-03-27T00:31:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"a66ea1f6-6dcc-4450-b06f-8732e722d5c1","html_url":"https://github.com/ekstroem/DKcpr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekstroem%2FDKcpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekstroem%2FDKcpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekstroem%2FDKcpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekstroem%2FDKcpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ekstroem","download_url":"https://codeload.github.com/ekstroem/DKcpr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245498417,"owners_count":20625176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T04:10:42.363Z","updated_at":"2025-10-13T04:03:47.527Z","avatar_url":"https://github.com/ekstroem.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DKcpr\n\n## Working with Danish CPR numbers in R\n\n\nThis note explains how to work with the Danish CPR numbers in R. The\nmajority of the information contained here is based on this wonderful\n[Wikipedia article](https://da.wikipedia.org/wiki/CPR-nummer).\n\nI've made an R package to handle validation of Danish cpr numbers. It\ncan be installed as follows:\n\n\n```r\n# Requires the devtools package to be installed in order to work\ndevtools::install_github(\"ekstroem/DKcpr\")\n```\n\n## Getting the date of birth\n\nThe first 6 digits of the CPR number represent date-of-birth in the\nformat DDMMYY. Since some people can live longer than 100 years the\ndate does not uniquely specify the year that a person was born. For\nexample, could the string `101010` represent October 10th 2010 or\nOctober 10th, 1910.\n\nThe 7th digit of the CPR number determines the century but the cut is\nnot trivial. Consequently, the `date_of_birth()` function returns the\ndate-of-birth as an R `Date` object in the format `YYYY-MM-DD`. As\ninput it accepts a vector of strings\n\nFor example:\n\n\n```r\nlibrary(\"DKcpr\")\ncpr \u003c- c(\"1010104321\", \"1010978726\", \"2310450637\", \"1010978726\")\ndate_of_birth(cpr)\n```\n\n```\n## [1] \"2010-10-10\" \"1897-10-10\" \"1945-10-23\" \"1897-10-10\"\n```\n\nWe get `NA` if we enter CPR numbers that refer to illegal dates, or do not match the format, or contains text.\n\n\n```r\ndate_of_birth(c(\"3510104321\", \"2902191234\", \"1111111\", \"Curious George\"))\n```\n\n```\n## Warning: 4 failed to parse.\n```\n\n```\n## [1] NA NA NA NA\n```\n\nWorking with the exact dates is easily done with the `lubridate`\npackage. For example, to extract the year we can use the `year()`\nfunction:\n\n\n```r\nlibrary(\"lubridate\")\ndob \u003c- date_of_birth(cpr)\nyear(dob)\n```\n\n```\n## [1] 2010 1897 1945 1897\n```\n\n## Verifying the validity of CPR numbes\n\nThe `is_cpr()` function can determine whether a CPR number is a valid\nCPR number. It returns `TRUE` if it is a valid CPR number, `FALSE` if\nit is not (i.e., is a date but does not fulfill the modulo 11 check), and `NA` if it is not a legal 10-digit number or date.\n\n\n```r\nis_cpr(cpr)\n```\n\n```\n## [1]  TRUE FALSE  TRUE FALSE\n```\n\n\n## Working with CPR numbers\n\nThe `gender()` function returns the gender of the individuals. 0 = female, 1 = male.\n\n\n```r\ngender(cpr)\n```\n\n```\n## [1] 1 0 1 0\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekstroem%2Fdkcpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fekstroem%2Fdkcpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekstroem%2Fdkcpr/lists"}