What is getage() Function in R

The getage() is a function from the eye package in R that calculates age in years, as durations or periods. It takes four arguments: from_date, to_date, period, and dec. The default value for to_date is the current date and time.


getage(from_date, to_date = lubridate::now(), period = FALSE, dec = 1)


from_date: It is a start date.

to_date: It is an end date.

period: Calculating period (TRUE) or duration (FALSEdefault).

dec: How many decimals are displayed?

Return value

It returns a numerical vector.


To use the getage() function, we need to install the “eye” package.


To load the “eye” package, you can use the library() function.


See the complete example of the getage() function.


dob <- c("1993-09-10", "1993-11-20")

test_date <- as.Date(dob) + c(15000, 20000)

getage(dob, test_date)


[1] 41.1 54.8

The getage() function takes two arguments: dob and test_date. dob is a character vector containing dates of birth in the format of “yyyy-mm-dd”.The test_date is a vector of dates for which age will be calculated.

The function returns a numeric vector of ages in years.

The output suggests that the age of the first person on the first test date is approximately 41.1 years, and the age of the second person on the second test date is approximately 54.8 years.

That’s it.

Leave a Comment