Skip to content

Instantly share code, notes, and snippets.

@jvieroe
Last active March 9, 2022 09:58
Show Gist options
  • Save jvieroe/1e581a5b8ec2f425278efcfc0ced57a8 to your computer and use it in GitHub Desktop.
Save jvieroe/1e581a5b8ec2f425278efcfc0ced57a8 to your computer and use it in GitHub Desktop.
library(lubridate)
# create fake CPR
cpr <- "181292-1731"
# get DOB
bdate <- stringr::str_sub(cpr, 1, 6)
# convert to date
bdate <- lubridate::dmy(bdate)
# calculate age
today <- Sys.Date()
trunc((bdate %--% today) / years(1))
# credits:
# https://datacornering.com/how-to-calculate-age-in-r/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment