1
library(eeptools)
x <- as.Date(c(01/01/1998, 'BirthDate'))
age_calc(x[1],x[2]) # default is age in months

Want to have the age in years between an initial age in days/month/years to the date 01/01/1998. I have more than 52000 birthdates ?

Hey, it still not working : as.numeric(01/01/1998 - BirthDate)/365.25 Error in eval(expr, envir, enclos): object 'BirthDate' not found Traceback

PhilBoaz
  • 27
  • 2

1 Answers1

1

Some base R possibilities could be:

as.numeric(format(x, "%Y")) - as.numeric(format(bday, "%Y"))

[1] 38 28

as.numeric(x - bday)/365.25

[1] 38.00137 28.00000

Sample data:

x <- as.Date("01/01/1998", format = "%d/%m/%Y")
bday <- as.Date(c("01/01/1960", "01/01/1970"), format = "%d/%m/%Y")
tmfmnk
  • 31,986
  • 3
  • 26
  • 41
  • Hey, it still not working : as.numeric(01/01/1998 - BirthDate)/365.25 Error in eval(expr, envir, enclos): object 'BirthDate' not found Traceback: – PhilBoaz Jun 16 '19 at 21:54