Package 'ageg'

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

Help Index


Age to Group

Description

Function that converts numeric age values to user defined age groups.

Usage

a2g(ages, mydist)

Arguments

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.

Value

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.

Examples

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"

Date to Age

Description

Function that converts a Date class vector of birth date values to numeric age values. This function is preparative to the a2g function.

Usage

d2a(bd)

Arguments

bd

Vector of Date class values. The date "yyyy-mm-dd" format is expected.

Value

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.

Examples

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