age | R Documentation |
\
age()
computes the year age of a person considering a reference date point.
age(birth_date, reference_date = base::Sys.Date(), round = FALSE)
birth_date |
A |
reference_date |
(optional) a |
round |
(optional) a |
A numeric
object with a year age.
## Scalar example
birth_date <- lubridate::as_date("2000-01-01")
reference_date <- lubridate::as_date("2020-01-01")
age(birth_date, reference_date, round = FALSE)
#> [1] 19.99722 # Expected
age(birth_date, reference_date, round = TRUE)
#> [1] 20
# Note that some years are not equal to exactly 365 days.
## Vector example
birth_date <- lubridate::as_date(c(
"1800-01-01", "1900-01-01", "2000-01-01"
))
reference_date <- lubridate::as_date("2020-01-01") # length == 1
age(birth_date, reference_date)
#> [1] 220.00000 120.00000 19.99722 # Expected
birth_date <- lubridate::as_date(c(
"1800-01-01", "1900-01-01", "2000-01-01"
))
reference_date <- lubridate::as_date(c( # same length as `birth_date`
"1900-01-01", "2000-01-01", "2020-01-01"
))
age(birth_date, reference_date)
#> [1] 100.00000 100.00000 19.99722 # Expected
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.