I tried following this R example for calculating age using three different methods:
- Efficient and accurate age calculation...LINK
Here's a sample of my script:
date_conversion_test <- copy(RawData[, dob := dob])
date_conversion_test[, givendate := Sys.Date()][, arithmetic := as.numeric((givendate - dob)/365.25)]
date_conversion_test[, lubridate := interval(start = dob, end = givendate)/yr]
date_conversion_test[, eeptools := age_calc(dob = dob, enddate = Sys.Date(), units = "years")]
I get this error:
> date_conversion_test[, eeptools := age_calc(dob, enddate = Sys.Date(), units = "years")]
Error in if (any(enddate < dob)) { :
missing value where TRUE/FALSE needed
How do I correct it to make the script syntax to ensure the eeptools
portion runs properly?
Here is some additional information:
> dput(head(date_conversion_test))
structure(list(dob = structure(c(6583, 724, 3574, 1189, 782,
2349), class = "Date"), givendate = structure(c(18522, 18522,
18522, 18522, 18522, 18522), class = "Date"), arithmetic = c(32.6872005475702,
48.7282683093771, 40.9253935660507, 47.4551676933607, 48.5694729637235,
44.2792607802875), lubridate = c(32.6872005475702, 48.7282683093771,
40.9253935660507, 47.4551676933607, 48.5694729637235, 44.2792607802875
), enddate = structure(c(18522, 18522, 18522, 18522, 18522, 18522
), class = "Date")), row.names = c(NA, -6L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x0000029362031ef0>)