1
0
mirror of https://github.com/msberends/AMR.git synced 2025-08-14 22:55:19 +02:00
Files
.github
PythonPackage
R
data
data-raw
inst
man
figures
AMR-deprecated.Rd
AMR-options.Rd
AMR.Rd
WHOCC.Rd
WHONET.Rd
ab_from_text.Rd
ab_property.Rd
add_custom_antimicrobials.Rd
add_custom_microorganisms.Rd
age.Rd
age_groups.Rd
antibiogram.Rd
antimicrobial_selectors.Rd
antimicrobials.Rd
as.ab.Rd
as.av.Rd
as.disk.Rd
as.mic.Rd
as.mo.Rd
as.sir.Rd
atc_online.Rd
av_from_text.Rd
av_property.Rd
availability.Rd
bug_drug_combinations.Rd
clinical_breakpoints.Rd
count.Rd
custom_eucast_rules.Rd
dosage.Rd
eucast_rules.Rd
example_isolates.Rd
example_isolates_unclean.Rd
export_ncbi_biosample.Rd
first_isolate.Rd
g.test.Rd
get_episode.Rd
ggplot_pca.Rd
ggplot_sir.Rd
guess_ab_col.Rd
intrinsic_resistant.Rd
italicise_taxonomy.Rd
join.Rd
key_antimicrobials.Rd
kurtosis.Rd
like.Rd
mdro.Rd
mean_amr_distance.Rd
microorganisms.Rd
microorganisms.codes.Rd
microorganisms.groups.Rd
mo_matching_score.Rd
mo_property.Rd
mo_source.Rd
pca.Rd
plot.Rd
proportion.Rd
random.Rd
resistance_predict.Rd
skewness.Rd
top_n_microorganisms.Rd
translate.Rd
pkgdown
tests
vignettes
.Rbuildignore
.gitignore
AMR.Rproj
CRAN-SUBMISSION
DESCRIPTION
LICENSE
NAMESPACE
NEWS.md
README.md
_pkgdown.yml
codecov.yml
cran-comments.md
index.md
logo.svg
AMR/man/age_groups.Rd

77 lines
2.6 KiB
R

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/age.R
\name{age_groups}
\alias{age_groups}
\title{Split Ages into Age Groups}
\usage{
age_groups(x, split_at = c(12, 25, 55, 75), na.rm = FALSE)
}
\arguments{
\item{x}{age, e.g. calculated with \code{\link[=age]{age()}}}
\item{split_at}{values to split \code{x} at - the default is age groups 0-11, 12-24, 25-54, 55-74 and 75+. See \emph{Details}.}
\item{na.rm}{a \link{logical} to indicate whether missing values should be removed}
}
\value{
Ordered \link{factor}
}
\description{
Split ages into age groups defined by the \code{split} argument. This allows for easier demographic (antimicrobial resistance) analysis.
}
\details{
To split ages, the input for the \code{split_at} argument can be:
\itemize{
\item A \link{numeric} vector. A value of e.g. \code{c(10, 20)} will split \code{x} on 0-9, 10-19 and 20+. A value of only \code{50} will split \code{x} on 0-49 and 50+.
The default is to split on young children (0-11), youth (12-24), young adults (25-54), middle-aged adults (55-74) and elderly (75+).
\item A character:
\itemize{
\item \code{"children"} or \code{"kids"}, equivalent of: \code{c(0, 1, 2, 4, 6, 13, 18)}. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.
\item \code{"elderly"} or \code{"seniors"}, equivalent of: \code{c(65, 75, 85)}. This will split on 0-64, 65-74, 75-84, 85+.
\item \code{"fives"}, equivalent of: \code{1:20 * 5}. This will split on 0-4, 5-9, ..., 95-99, 100+.
\item \code{"tens"}, equivalent of: \code{1:10 * 10}. This will split on 0-9, 10-19, ..., 90-99, 100+.
}
}
}
\examples{
ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21)
# split into 0-49 and 50+
age_groups(ages, 50)
# split into 0-19, 20-49 and 50+
age_groups(ages, c(20, 50))
# split into groups of ten years
age_groups(ages, 1:10 * 10)
age_groups(ages, split_at = "tens")
# split into groups of five years
age_groups(ages, 1:20 * 5)
age_groups(ages, split_at = "fives")
# split specifically for children
age_groups(ages, c(1, 2, 4, 6, 13, 18))
age_groups(ages, "children")
\donttest{
# resistance of ciprofloxacin per age group
if (require("dplyr") && require("ggplot2")) {
example_isolates \%>\%
filter_first_isolate() \%>\%
filter(mo == as.mo("Escherichia coli")) \%>\%
group_by(age_group = age_groups(age)) \%>\%
select(age_group, CIP) \%>\%
ggplot_sir(
x = "age_group",
minimum = 0,
x.title = "Age Group",
title = "Ciprofloxacin resistance per age group"
)
}
}
}
\seealso{
To determine ages, based on one or more reference dates, use the \code{\link[=age]{age()}} function.
}