# Calculating Age

Both ‘first’ and ‘second’ need to be date vectors. This is to achieve a calculation of age rounded DOWN in the same way that we say our age (as in we say 17, right up until the day we turn 18). round(x,0) will round up, floor(x) will also cause issues, if the two dates are the same day of the same month but on different years.

EDIT: This had an error and has been superseded by this post.

## 5 thoughts on “Calculating Age”

1. This unfortunately does not work if birth day is 29 Feb and “second” is any date in non-leap-year.

> age_years(as.Date(“2000-02-29”), as.Date(“2013-02-27”))
Error in charToDate(x) : character string is not in a standard unambiguous format

• Well spotted, this has now been fixed up.

2. Maybe you can clarify for me the utility of doing this. If someone is 17.999 years old he or she is still under 18. Why round ages at all? Is there some compelling reason to represent age as integers? Typically I’m asked to put ages into ranges and have no need to round up or down.

• There’s a few reasons you might like to do this.
– If you have a requirement of people to be exactly ’18’ or ’25’ before entering something, then you need their age spot on as you can’t have them creeping into the category a day early because of dud rounding.
– If you are working on data with 1,000’s of children say and have tight age categories 10-12, 13-15 etc, you don’t want lot’s of children getting assigned to the wrong group because of rounding issues that can occur with cruder methods.