How to Change a Birthday Object to Age in R (Example Code)

In this tutorial, I’ll illustrate how to switch a birthday date to the age in the R programming language.

Creation of Example Data

dob <- as.Date("1985-11-05")                  # Specify date of birth
dob
# [1] "1985-11-05"
dto <- Sys.Date()                            # Save date of today
dto
# [1] "2021-09-02"

Example: Apply age_calc() Function of eeptools Package to Convert Date of Birth to Age

install.packages("eeptools")                  # Install & load eeptools package
library("eeptools")
floor(age_calc(dob, dto, units = "years"))    # Calculate age
# [1] 35

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top