Split Ages Into Age Groups - R
Maybe your like
| age_groups {AMR} | R Documentation |
Split Ages into Age Groups
Description
Split ages into age groups defined by the split argument. This allows for easier demographic (antimicrobial resistance) analysis.
Usage
age_groups(x, split_at = c(12, 25, 55, 75), na.rm = FALSE)Arguments
| x | age, e.g. calculated with age() |
| split_at | values to split x at - the default is age groups 0-11, 12-24, 25-54, 55-74 and 75+. See Details. |
| na.rm | a logical to indicate whether missing values should be removed |
Details
To split ages, the input for the split_at argument can be:
A numeric vector. A value of e.g. c(10, 20) will split x on 0-9, 10-19 and 20+. A value of only 50 will split 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+).
A character:
-
"children" or "kids", equivalent of: c(0, 1, 2, 4, 6, 13, 18). This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.
-
"elderly" or "seniors", equivalent of: c(65, 75, 85). This will split on 0-64, 65-74, 75-84, 85+.
-
"fives", equivalent of: 1:20 * 5. This will split on 0-4, 5-9, ..., 95-99, 100+.
-
"tens", equivalent of: 1:10 * 10. This will split on 0-9, 10-19, ..., 90-99, 100+.
-
Value
Ordered factor
See Also
To determine ages, based on one or more reference dates, use the age() function.
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") # 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" ) } [Package AMR version 2.1.1 Index]Tag » How To Group Ages In Rstudio
-
Dplyr Way(s) And Base R Way(s) Of Creating Age Group From Age
-
Split Ages Into Age Groups — Age_groups • AMR (for R)
-
Create Agegroups In R Using The Patients Ages. Code Included.
-
How To Group Ages In Specific Range Using R - Stack Overflow
-
Put Ages Into Age Groups - RPubs
-
How To Group Age In Data Graph? : R/RStudio - Reddit
-
AgeGroups: Return A Factor Variable Of Age Groups - RDocumentation
-
6.3 Group_by() And Ungroup() | R For Graduate Students - Bookdown
-
How To Use Anova Test In R Studio To Find Whether The Age Group ...
-
Chapter 10 Dplyr - Data Manipulation | Tabular Data Analysis With R ...
-
Basic Statistical Analysis Using The R Statistical Package - SPH
-
13 Grouping Data | The Epidemiologist R Handbook
-
How To Count By Group In R - InfoWorld