1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 06:46:11 +01:00
AMR/man/age.Rd

57 lines
2.8 KiB
Plaintext
Raw Normal View History

2018-12-15 22:40:07 +01:00
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/age.R
\name{age}
\alias{age}
\title{Age in Years of Individuals}
2018-12-15 22:40:07 +01:00
\usage{
age(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE, ...)
2018-12-15 22:40:07 +01:00
}
\arguments{
2021-05-23 23:11:16 +02:00
\item{x}{date(s), \link{character} (vectors) will be coerced with \code{\link[=as.POSIXlt]{as.POSIXlt()}}}
2018-12-15 22:40:07 +01:00
2021-05-23 23:11:16 +02:00
\item{reference}{reference date(s) (defaults to today), \link{character} (vectors) will be coerced with \code{\link[=as.POSIXlt]{as.POSIXlt()}}}
2021-05-12 18:15:03 +02:00
\item{exact}{a \link{logical} to indicate whether age calculation should be exact, i.e. with decimals. It divides the number of days of \href{https://en.wikipedia.org/wiki/Year-to-date}{year-to-date} (YTD) of \code{x} by the number of days in the year of \code{reference} (either 365 or 366).}
2021-05-12 18:15:03 +02:00
\item{na.rm}{a \link{logical} to indicate whether missing values should be removed}
2020-12-22 00:51:17 +01:00
\item{...}{arguments passed on to \code{\link[=as.POSIXlt]{as.POSIXlt()}}, such as \code{origin}}
2018-12-15 22:40:07 +01:00
}
\value{
2020-03-07 21:48:21 +01:00
An \link{integer} (no decimals) if \code{exact = FALSE}, a \link{double} (with decimals) otherwise
2018-12-15 22:40:07 +01:00
}
\description{
2019-01-12 11:06:58 +01:00
Calculates age in years based on a reference date, which is the sytem date at default.
2018-12-15 22:40:07 +01:00
}
\details{
Ages below 0 will be returned as \code{NA} with a warning. Ages above 120 will only give a warning.
2021-05-23 23:11:16 +02:00
This function vectorises over both \code{x} and \code{reference}, meaning that either can have a length of 1 while the other argument has a larger length.
}
\section{Stable Lifecycle}{
\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:"5"} \cr}
2020-07-08 14:48:06 +02:00
The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.
2022-03-10 19:33:25 +01:00
If the unlying code needs breaking changes, they will occur gradually. For example, an argument will be deprecated and first continue to work, but will emit a message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
}
\section{Read more on Our Website!}{
2019-01-02 23:24:07 +01:00
2021-06-01 15:33:06 +02:00
On our website \url{https://msberends.github.io/AMR/} you can find \href{https://msberends.github.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR data analysis, the \href{https://msberends.github.io/AMR/reference/}{complete documentation of all functions} and \href{https://msberends.github.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}.
2019-01-02 23:24:07 +01:00
}
2019-01-25 13:18:41 +01:00
\examples{
# 10 random birth dates
df <- data.frame(birth_date = Sys.Date() - runif(10) * 25000)
# add ages
2019-01-25 13:18:41 +01:00
df$age <- age(df$birth_date)
# add exact ages
df$age_exact <- age(df$birth_date, exact = TRUE)
df
2019-01-25 13:18:41 +01:00
}
2018-12-15 22:40:07 +01:00
\seealso{
To split ages into groups, use the \code{\link[=age_groups]{age_groups()}} function.
2018-12-15 22:40:07 +01:00
}