mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 16:42:10 +02:00
age_groups fix
This commit is contained in:
12
R/age.R
12
R/age.R
@ -73,8 +73,8 @@ age <- function(x, reference = Sys.Date()) {
|
||||
#' \itemize{
|
||||
#' \item{\code{"children"}, 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, 95)}. This will split on 0-64, 65-74, 75-84, 85-94 and 95+.}
|
||||
#' \item{\code{"fives"}, equivalent of: \code{1:20 * 5}. This will split on 0-4, 5-9, 10-14, 15-19 and so forth.}
|
||||
#' \item{\code{"tens"}, equivalent of: \code{1:10 * 10}. This will split on 0-9, 10-19, 20-29 and so forth.}
|
||||
#' \item{\code{"fives"}, equivalent of: \code{1:24 * 5}. This will split on 0-4, 5-9, 10-14, 15-19 and so forth, until 120.}
|
||||
#' \item{\code{"tens"}, equivalent of: \code{1:12 * 10}. This will split on 0-9, 10-19, 20-29 and so forth, until 120.}
|
||||
#' }
|
||||
#' }
|
||||
#' @keywords age_group age
|
||||
@ -92,11 +92,11 @@ age <- function(x, reference = Sys.Date()) {
|
||||
#' age_groups(ages, c(20, 50))
|
||||
#'
|
||||
#' # split into groups of ten years
|
||||
#' age_groups(ages, 1:10 * 10)
|
||||
#' age_groups(ages, 1:12 * 10)
|
||||
#' age_groups(ages, split_at = "tens")
|
||||
#'
|
||||
#' # split into groups of five years
|
||||
#' age_groups(ages, 1:20 * 5)
|
||||
#' age_groups(ages, 1:24 * 5)
|
||||
#' age_groups(ages, split_at = "fives")
|
||||
#'
|
||||
#' # split specifically for children
|
||||
@ -122,9 +122,9 @@ age_groups <- function(x, split_at = c(12, 25, 55, 75)) {
|
||||
} else if (split_at %like% "^(elder|senior)") {
|
||||
split_at <- c(65, 75, 85, 95)
|
||||
} else if (split_at %like% "^five") {
|
||||
split_at <- 1:20 * 5
|
||||
split_at <- 1:24 * 5
|
||||
} else if (split_at %like% "^ten") {
|
||||
split_at <- 1:10 * 10
|
||||
split_at <- 1:12 * 10
|
||||
}
|
||||
}
|
||||
split_at <- as.integer(split_at)
|
||||
|
Reference in New Issue
Block a user