Title: | Age Grouping Functions |
---|---|
Description: | Pair of simple convenience functions to convert a vector of birth dates to age and age distributions. These functions may be helpful when related age and custom age distributions are desired given a vector of birth dates. |
Authors: | Austin Anders [aut, cre] |
Maintainer: | Austin Anders <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-15 03:35:15 UTC |
Source: | https://github.com/cran/ageg |
Function that converts numeric age values to user defined age groups.
a2g(ages, mydist)
a2g(ages, mydist)
ages |
Vector of Numeric class age values. |
mydist |
Vector of Character class age distributions. Values must be two integers separated by a hyphen. Remove any whitespaces on either side of the hyphen. |
Returns a Character class vector object of age distribution values defined by the mydist argument. The function will otherwise return an error message stating that the function requires a numeric class object.
ages <- c(3, 101, 42, 32) mydist <- c("5-10","11-20","21-30","31-40","41-50","51-60","61-70","71+") a2g(ages, mydist) # > a2g(ages, mydist) # [1] NA "71+" "41-50" "31-40"
ages <- c(3, 101, 42, 32) mydist <- c("5-10","11-20","21-30","31-40","41-50","51-60","61-70","71+") a2g(ages, mydist) # > a2g(ages, mydist) # [1] NA "71+" "41-50" "31-40"
Function that converts a Date class vector of birth date values to numeric age values. This function is preparative to the a2g function.
d2a(bd)
d2a(bd)
bd |
Vector of Date class values. The date "yyyy-mm-dd" format is expected. |
Returns a numeric class vector object of ages if the function is provided a Date class object. The function will otherwise return an error message stating that the function requires a Date class object.
datevals <- as.Date(c("2019-01-01","1920-12-12","1980-02-02","1991-03-03" )) d2a(datevals) # > d2a(datevals) # [1] 3 101 42 31
datevals <- as.Date(c("2019-01-01","1920-12-12","1980-02-02","1991-03-03" )) d2a(datevals) # > d2a(datevals) # [1] 3 101 42 31