#' Determine people's age
#'
#' Finds out the calendar year difference between two dates.
#'
#' @param givendate,birthdate Date vectors of equal length.
#'
#' @return An integer vector of the same length as \code{givendate}.
#' @details For \code{birthdate > givendate} \code{NA}s are returned .
#' @export
#' @import lubridate
calculate_age <- function(givendate, birthdate) {
stopifnot(is.Date(c(givendate, birthdate)))
output <- as.period(interval(birthdate, givendate))$year
output[output < 0] <- NA
output
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.